Search code examples
cordovaionic-frameworkpush-notificationapple-push-notificationspush

Ionic OneSignal Push notifications crashing IOS 14+ devices on boot


I am having a persistent issue with the app on IOS claiming to be on line 194 of OneSignalPush.m. I'm creating an Ionic 4 app with push notification capability. This seems to work perfectly on older IOS devices, but newer ones (IOS 14+) seem to crash.

https://github.com/OneSignal/OneSignal-Cordova-SDK/blob/22660bd5e48cc38c13b2e4268fa42d048ebbb94b/src/ios/OneSignalPush.m#L194

The last 10 items on the crash backtrace are:

Last Exception Backtrace:
0   CoreFoundation                  0x1af14a5ac __exceptionPreprocess + 220 (NSException.m:199)
1   libobjc.A.dylib                 0x1c323842c objc_exception_throw + 60 (objc-exception.mm:565)
2   CoreFoundation                  0x1af054a2c -[NSObject(NSObject) doesNotRecognizeSelector:] + 144 (NSObject.m:146)
3   CoreFoundation                  0x1af14d130 ___forwarding___ + 1444 (NSForwarding.m:3597)
4   CoreFoundation                  0x1af14f420 _CF_forwarding_prep_0 + 96
5   School Bozza                    0x1042d7620 -[OneSignalPush init:] + 676 (OneSignalPush.m:194)
6   School Bozza                    0x10432c68c 0x1042bc000 + 460428
7   School Bozza                    0x1042c7a90 -[CDVWKWebViewEngine handleCordovaMessage:] + 180 (CDVWKWebViewEngine.m:616)
8   School Bozza                    0x1042c794c -[CDVWKWebViewEngine userContentController:didReceiveScriptMessage:] + 124 (CDVWKWebViewEngine.m:602)
9   School Bozza                    0x1042c8c14 -[CDVWKWeakScriptMessageHandler userContentController:didReceiveScriptMessage:] + 100 (CDVWKWebViewEngine.m:822)
10  WebKit                          0x1bb3bd4c4 ScriptMessageHandlerDelegate::didPostMessage(WebKit::WebPageProxy&, WebKit::FrameInfoData&&, API::ContentWorld&, WebCore::SerializedScriptValue&) + 232 (WKUserContentController.mm:148)

Line 5 gives us what I think is the culprit.

Things I've already tried:

  • Older version of the Podfile
  • Remove and add back ios platform
  • Remove and add cordova plugin
  • Different versions of cordova plugin
  • Adding in a 'setTimeout' to delay the initialization somewhat

Nothing seems to work. I am initializing in my app.component.ts within the platform. ready function like this:

initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      setTimeout(() => {
        this.oneSignalInit();
        this.uId.get().then((uuid: any) => {});
      }, 1000);
    });
  }

And then I'm running the init like this:

oneSignalInit() {
    try {
      // set onesignal id
      const oldId = localStorage.getItem('onesignal_id');
      if (oldId && oldId.length > 0) {
        console.log('We have already registered with one signal');
      } else {
        if (this.platform.is('ios')) {
          this.oneSignal.addTrigger("prompt_ios", "true");
          this.oneSignal.startInit(environment.ONESIGNAL_APP_ID, '');
        } else {
          this.oneSignal.startInit(environment.ONESIGNAL_APP_ID, environment.FIREBASE_SENDERID);
        }
        // notification configuration
        this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification); 
        this.oneSignal.setSubscription(true);
        this.oneSignal.enableVibrate(true);
        this.oneSignal.enableSound(true);
        try {
          // get unique id from onesignal and register with device
          this.oneSignal.getIds().then((usersIds: any) => {
            console.log('Registered with onesignal');
            localStorage.setItem('onesignal_id', usersIds.userId);
          }).catch((err: any) => {
            console.log(err, 'one');
          });
        } catch (e) {
          console.log(e);
        }
      }
      this.oneSignal.endInit();
    } catch (e) {
      console.log(e, 'try');
      this.oneSignal.endInit();
    }
  }

Please if anyone can be of assistance, it would be amazing, I cant even imagine what the issue could be, others dont seem to face the same issue, so it must be something stupid that I'm doing.


Solution

  • Okay so I found the issue, so in my app initialization i used:

    this.oneSignal.startInit(environment.ONESIGNAL_APP_ID, ' ');

    But the issue was actually a null string, meaning that the app was not successfully importing the variable: "environment.ONESIGNAL_APP_ID".

    I fixed that by simply hardcoding the App ID in the actual "OneSignalPush.m" file... It's not good practice but it stops the app from crashing.