问题
I have implemented push notification in ionic Everything working fine on android and but in IOS got different scenario:
- in foreground : onNotification is not fired as well as android working perfect.
 - Background: push notification is received but after tap from notification nothing happend
 
app.component.ts
this.fcm.onNotification().subscribe(data => {
if(data.wasTapped){
  console.log(data.wasTapped);
     //redirectPageViaNotificationType for redirect page...
     this.redirectPageViaNotificationType(data);
}  else {
    //Notification was received in foreground. Maybe the user needs to be notified
      // if application open, show
    let confirmAlert = this.alertCtrl.create({
      title: (<any>data).title,
      message: (<any>data).body,
      buttons: [{
        text: 'Ignore',
        role: 'cancel'
      },{
        text: 'View',
        handler: () => {
            //redirectPageViaNotificationType for redirect page...
          this.redirectPageViaNotificationType(data);
        }
      }]
    });
    confirmAlert.present();
}
});
when any push notification is received its showing notification when my application is closed or background it does not executing the this.fcm.onNotification()function. And i just debug this issue and noticed this, in my xcode console its showing:
Tried Solution
Link :
Add "content_available":true in the notification payload but its not working for me.
https://forum.cometchat.com/t/ionic-push-notification-not-triggered-when-in-foreground-ios/620/8
remove Below plugin :
npm i cordova-plugin-fcm-with-dependecy-updated and local-notification plugin and add it again but not worked for me.
can any one please tell me why its happing and what's going wrong?
回答1:
I spent a lot of time on this problem, but I could not get the fcm plugin to work stably in ios. This problem was reproduced when the application was killed. I think the fcm plugin does not work too well with ios. I was trying to use phonegap-plugin-push and everything is working fine. This plugin can work with fcm and apns, and notification caught even when the ios application was killed.
回答2:
If you want to handle the requests, ie not just process some data in the background as you would with content-available: '1', you must leave it as content-available: '0'.
I process Push notifications with PHP and Kreait/Firebase. Then for iOS this is my config:
  $notification = Notification::fromArray([
    'title' => $title,
    'body'  => $message,
  ]);
  $data = MessageData::fromArray([
    'some_key' => $value,
  ]);
  $apnsConfig = ApnsConfig::fromArray([
    'payload' => [
      'aps' => [
        'badge' => 1,
        'content-available' => 0,
        'notId' => UUID::v4()
      ],
    ],
  ]);
  $cloudMessage = CloudMessage::new()
    ->withNotification($notification)
    ->withData($data)
    ->withApnsConfig($apnsConfig);
  $apnsResult = self::$messaging->sendMulticast($cloudMessage, $iosTokens);
You can find the documentation here: https://firebase.google.com/docs/cloud-messaging. For Android I used curl however, there was some problem back then with kreaits' fcm implementation. They did publish a new release that I ment to check whether it fixed this.
Hope this helps.
来源:https://stackoverflow.com/questions/62410530/ionic-3-onnotification-not-fire-in-foreground-in-ios