OneSignal: handleNotificationOpened not getting triggered when cold start


#1

It works when app is running in background and i click on received notification but not working when coldstart from received notification.
.

  shared.LS.get('user').then((data: any) => {
      if (!data) {
        this.rootPage = AuthPage;
      } else {
        this.globalProvider.setAuthData(data);
        this.rootPage = TabsPage;
      }
    });
    platform.ready().then(() => {  

      if (platform.is('cordova')) {

        this.oneSignal.startInit('**********', '*****************');

        this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);

        this.oneSignal.handleNotificationReceived().subscribe((data) => { 
          console.log(data);
        });
        this.oneSignal.handleNotificationOpened().subscribe((data) => { 
          console.log(data);
          let type
          try {
              type = data.notification.payload.additionalData.type;
          } catch (e) {
            console.warn(e);
          }
          switch (type) {
            case 'Followers': {
              this.navController.push(UserProfilePage, {userId: data.notification.payload.additionalData.uid})
            break; 
            }
          }
        });
        this.oneSignal.endInit(); 
      }



#2

What platform are you talking about?

If I remember correctly either Android or iOS doesn’t deliver the notification payload to the app by default if you open the app not via the notification (while a notification is in the notification center).


#3

Have you got the solution yet ?


#4

Yes @kaushikmishra6, it was getting triggered but before rootPage initialization, so try to change the navigation after rootPage initialization. I used event for that

   this.oneSignal.handleNotificationOpened().subscribe((data) => {
          console.log(data);
          let payload = data;
          if (this._isColdStart) {
            events.subscribe('root:created', (data) => {
              this.redirectToPage(payload);
              events.unsubscribe('root:created');
            });
          } else {
            this.redirectToPage(data);
          }
        });

And tabs.ts

ionViewDidLoad() { 
    this.events.publish('root:created', Date.now());
  }

#5

I am not getting it what you are trying to say


#6

I was not talking about platform, platform.ready is to ensure that all plugins loaded, and platform.is('cordova') to prevent cordova_not_available in browser.

And you are right Android or iOS doesn’t deliver notification payload, onesignal an ionic naitve push notification plugin doing that work.


#7

What is this?
I also have a problem on IOS with notification when the app is closed.