0
votes

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:

xcode capabilities

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.

2

2 Answers

0
votes

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"
 }
-1
votes

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.