iOS app doesn't receive background push notifications from Firebase

最后都变了- 提交于 2020-01-06 06:08:14

问题


I'm trying to get push notifications working in a Cordova app I'm working on. They work perfectly in the Android app and they work perfectly in the iOS app when it's in the foreground, but I don't receive any notifications when the app is in the background or terminated.

I have the "Push Notifications" and "Background Modes - Remote notifications" capabilities enabled:

And I'm 100% sure the server has the device token (since push notifications are working in the foreground, and I can see it in the database).

This is how I'm sending the push notification using the firebase-admin node module:

await firebase.messaging().send({
  token: userDeviceToken,
  data: {foo: 'bar'},
  notification: {
    title: 'This is a notification title',
    body: 'This is a notification body',
  },
});

What am I missing?

EDIT:

If I launch the app or bring it to the foreground after it was supposed to receive a notification, it acts like it received an in-app notification. This happens even if I wait several minutes after the notification was sent before launching the app.


回答1:


You cannot receive remote notifications when the app is terminated. You may want to show a local notification telling the user that he cannot receive notifications anymore when the app is terminated.




回答2:


Check the payload structure you received in the app while foreground. Normally it's different compared to Android. The iOS payload structure should be :

{
   "aps" : {
     "alert" : {
       "body" : "great match!",
       "title" : "Portugal vs. Denmark",
     },
     "badge" : 1,
   },
   "Custom_Data" : "Game level name"
 }


来源:https://stackoverflow.com/questions/53328878/ios-app-doesnt-receive-background-push-notifications-from-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!