cordovapush-notificationibm-cloudibm-mobile-services

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


I've implemented an Ionic test application using the new bms-push cordova plugin.

It works fine on Android.

However, when launching the app on iOS, it immediately fails with:

fatal error: unexpectedly found nil while unwrapping an Optional value

The error occurs in the didReceiveRemoteNotificationOnLaunch function of the CDVBMSPush class.

If I comment out the following line in the AppDelegate.m

[[CDVBMSPush sharedInstance] didReceiveRemoteNotificationOnLaunchWithLaunchOptions:launchOptions];

then the app starts properly.

Any suggestion to fix the problem please? Thx


Solution

  • Just got an answer from the support team:

    [[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.