Cordova Firebase background push notifications not working in iOS13 and XCode 11?

What a pain! Push notifications work when the app is in the foreground, but had stopped when the app is in the background. I’d update my app too!

I am using cordova-plugin-firebase, which is being kept upto date more than  cordova-plugin-fcm

There are 2 reason for this that I have found!

1) XCode 11 doesn’t remember some of the previous capabilities. It remembered push notifications, but not background modes!

You need to make sure BackgroundModes is added (little + to the left of Capability) and then check  Remote Notifications

Background Push modes

 

2) The POST to Firebase needs adding too with some APNS headers

Here is my PHP code with the extra APNS headers. All learned from https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages  and https://onesignal.com/blog/ios-13-introduces-4-breaking-changes-to-notifications/

And then…. Android. Ouch.

I have been using cordova-plugin-firebase which is now no good – you need to use a fork…

cordova-plugin-firebasex

Then you need to add cordova-plugin-androidx and cordova-plugin-androidx-adapter

But not before youhave updated Cordova to v9.0.0 and Cordova Android>=8.0 Aaaagh.

And then made some changes in your code from cordova-plugin-firebase to cordova-plugin-firebasex

  • onNotificationOpen() renamed to onMessageReceived()
    • tap parameter is only set when user taps on a notification (not when a message is received from FCM)
    • tap=foreground|background instead of tap=true|false
  • hasPermission() receives argument as a boolean (rather than an object with isEnabled key)
    • e.g. window.FirebasePlugin.hasPermission(function(hasPermission){ console.log("Permission is " + (hasPermission ? "granted" : "denied")); });

Then you need some notification icons – single colour transparent pngs

Place them in the folder and update config.xml like so

And also add this

Then it all worked first time. Unbelievable!

But all this also means some more changes for iOS in a moment!!!

FirebaseX uses cocoapods

so you need to install that

Then after a cup of tea or two…

Check it installed with

Go to to the platforms/ios directory and

After another tea or beer, you can build ios and that works finally with sounds too! Hurrah.

 


Leave a Reply