ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push

Receiving "fatal error: unexpectedly found nil while unwrapping an Optional value" when launching app in iOS

Closed this issue · 4 comments

Hi,

When I launch my Ionic test application 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

Hi @jmereaux , You don't have to add

[[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];
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
      [[CDVBMSPush sharedInstance] didReceiveRemoteNotificationOnLaunchWithLaunchOptions:launchOptions];
    }
}

  1. Completely remove that line of code.

Hope this will help ...

Hi @AnanthaKrish
This helps a lot, thanks.
I suggest you add this to the documentation :-)

The docs has a not ("!") before the launchOptions...?!