bms-push cordova plugin on iOS gives: fatal error: unexpectedly found nil while unwrapping an Optional value

bms-push cordova plugin on iOS gives: fatal error: unexpectedly found nil while unwrapping an Optional value

我已经使用新的 bms-push cordova 插件实现了一个 Ionic 测试应用程序。

它在 Android 上工作正常。

然而,当在 iOS 上启动应用程序时,它立即失败并显示:

fatal error: unexpectedly found nil while unwrapping an Optional value

错误发生在CDVBMSPushclass的didReceiveRemoteNotificationOnLaunch函数中。

如果我在 AppDelegate.m

中注释掉以下行

[[CDVBMSPush sharedInstance] didReceiveRemoteNotificationOnLaunchWithLaunchOptions:launchOptions];

然后应用程序正常启动。

有什么解决问题的建议吗? 谢谢

刚从支持团队那里得到 answer

[[CDVBMSPush sharedInstance] didReceiveRemoteNotificationOnLaunchWithLaunchOptions:launchOptions];

This is only used when app is opened by clicking push notifications.

At the first time launchOptions will be nil. That why its failing.

Solutions:

  1. you can add a check there whether the launchOptions is of type remoteNotificationKey, If yes then add the [[CDVBMSPush sharedInstance] didReceiveRemoteNotificationOnLaunchWithLaunchOptions:launchOptions];

Example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
      [[CDVBMSPush sharedInstance] didReceiveRemoteNotificationOnLaunchWithLaunchOptions:launchOptions];
    }
}
  1. Completely remove that line of code.