【问题标题】:AppDelegate unrecognized selector sent to instanceAppDelegate 无法识别的选择器发送到实例
【发布时间】:2021-11-06 07:26:49
【问题描述】:

我正在做一个项目,我正在实现这个 SDK https://docs.drivequant.com/trip-analysis/ios/get-started,我正在 appdelegeate.m 中实现它

这里我如何导入模块

@import DriveKitCoreModule;
@import DriveKitTripAnalysisModule;

这里是我如何初始化它

[[DriveKit shared] initialize];
  [[DriveKit shared] setApiKeyWithKey: @""];
  [[DriveKit shared] setUserIdWithUserId: @""];
  [[DriveKit shared] enableLoggingWithShowInConsole:YES];
 
  [[DriveKitTripAnalysis shared] initializeWithTripListener: self appLaunchOptions:launchOptions];

但我总是通过 initializeWithTripListener 收到此警告

运行后出现此错误

有人知道我为什么会收到这个错误吗?以及如何解决?

【问题讨论】:

  • 您缺少这部分Make the AppDelegate class implement TripListener protocol,它解释了警告和编译器错误...
  • 你有这样做的例子吗?谢谢你
  • 你的代码是 Objective-C。您可能应该删除问题上的swift 标签,因为只知道 Swift 的人将无法帮助您。

标签: objective-c xcode


【解决方案1】:

请参阅this link,了解如何声明 Objective-C 类符合协议。 (特别是标题为“符合协议”的部分。)

查看您正在使用的框架的自述文件,它说:

使 AppDelegate 类实现 TripListener 协议。该协议包含 6 种实现方法:

func tripPoint(tripPoint: TripPoint) {
}
func tripStarted(startMode: StartMode) {
}
func tripCancelled(cancelTrip: CancelTrip) {
}
func tripFinished(post: PostGeneric, response: PostGenericResponse) {
}
func tripSavedForRepost(){
}
func beaconDetected(){
}
func significantLocationChangeDetected(location: CLLocation){
}
func sdkStateChanged(state: State){
}

因此,您需要将这 6 种方法的实现添加到您的应用委托中。 (这些方法声明在 Swift 中。如果您使用 Objective-C 编写应用程序委托,则需要找到 Objective-C 函数原型。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2012-07-24
    相关资源
    最近更新 更多