Nothing happens after receiving notification in iOS


#1

I have a application which has push notification functionality and i am receiving notification successfully in both android and ios using cordova-plugin-fcm.

this is my code where i receive notification.

FCMPlugin.onNotification(
          function(data){
              if(data.wasTapped){

                  //Notification was received on device tray and tapped by the user.
                  this.handleNotification(data);
              }else{
                  //Notification was received in foreground. Maybe the user needs to be notified.
                  alert("Notification received in foreground"); // this alert is generated
                  let alert1 = this.alertCtrl.create({      /// whereas this alert controller is not generated
                  title: 'You have got a new Notification.',
                  message: data.notificationDescription,
                  buttons: [
                    {
                      text: 'Ignore',
                      role: 'cancel',
                      handler: () => {
                        console.log('Cancel clicked');
                      }
                    },
                    {
                      text: 'View',
                      handler: () => {
                        this.handleNotification(data);
                      }
                    }
                  ]
                });
                alert1.present();
              }
          },
          function(msg){
              console.log('onNotification callback successfully registered: ' + msg);
          },
          function(err){
              console.log('Error registering onNotification callback: ' + err);
          }
      );

    });

As you can see i have created a function which handles notification data after receiving notification if user wants to view that particular notification.


handleNotification(data){
    alert("inside handle notification");   /// this alert is not being generated so it means it doesn't come to this function
    
    if(data.isShowDetail){
      alert("if data.isShowDetail is set");
    }
    else if(data.isRedirect){
      else if(data.redirectScreen == 1){
        //Home Page
        this.nav.push(TabsPage);
      }
      else if(data.redirectScreen == 2) {
        //news
        this.nav.push(NewsPage);
      }
    }
    else{
      alert("inside last condition");
      this.nav.push(NotificationPage);
    }
  }

What is the issue here or is there any other way to handle notification like the way i want?


Http IONIC push notification request
Ionic Deploy - How to delete a snapshot?
How to receive additional data for Push notification in ionic2
#2

Your post is quite confusing.
What is working?
What isn’t working?


#3

I have written in comment that
alert("Notification received in foreground");
this alert is generated after notification received and when app is opened.
but after clicking ok that alert Controller is not being created to handle that notification.
And that way i can’t send notification data the notification handler function when user clicks View button from alert controller.

Also that function is not called when app is closed and when i open the application.

I have written comments where it’s necessary.


#4

So your real problem is not that “nothing happens” as you stated in the title but that the alertCtrl you try to present doesn’t present. Everything else is unrelevant for now. Correct?

Replace the alert() with a console.log that doesn’t pause the program’s execution.
Check that all data for the alertCtrl is present.

What “that function”? onNotification? On which platform? Pushes received are handled differently depending on the OS you are testing on.


#5

I was talking about this.handleNotification(data); function.
which is called from view button in alertController.

I have placed that function’s code in last.


#6

If the alertController is not opened, noone can push the “view button” there and so the function can not be called. Right?

If you meant with the “app is in background when notification is received, nothing happens where I open it” then the handleNotification() is only called when data.wasTapped is true. Is it? Add a console.log to your code inside and before that if to debug.

PS: I would suggest you concentrate on one of these two issues (alertCtrl not working, background notification not handled when entering app) in this thread and opening a new one for the second issue - this is mighty confusing, especially if you don’t quote correctly what you are answering to.