NativeScript Firebase onMessageReceivedCallback does not fire on iOS

Viewed 546

I am using NativeScript-Vue (7.0) and using this code to initialize Firebase:

firebase.init({
        onMessageReceivedCallback: (message) => {
          console.log("[Firebase] onMessageReceivedCallback:", { message });
        },
        onPushTokenReceivedCallback: (token) => {
          console.log("[Firebase] onPushTokenReceivedCallback:", { token });
        },
      })
      .then(() => console.log("Firebase initialised."));

Everything works fine on Android, but on iOS (on simulator as well as on a real device) two things are happening:

  1. onPushTokenReceivedCallback is fired TWICE (with same token)
  2. onMessageReceivedCallback is never fired even when app is in foreground.

I am using FCM Dashboard to send notifications, tried both Test as well as Campaign notification with custom data. It only worked in Android.

I understand there are complications in implementing background push notifications in iOS but in foreground when app is running, why isn't it receiving the message?

I am using this firebase plugin and I followed everything in the docs apart from one thing that is Enabling push support in Xcode as apparently this setting is gone from Xcode for free apple developer accounts. But I did add the entitlements manually as mentioned here.

Does receiving message call back require some special permission or am I missing out on something?

1 Answers

Unfortunately, I think you will have to enable the Push Notification capability in XCode.

Once you do that, if you are using @nativescript/ios: 7+ and @nativescript/firebase: 11.0.0 when you do get foreground notifications working, the app will crash. To get around this we had to use `@nativescript/ios: "6.5.3" (this uses the original JSC iOS runtime rather than the new V8 iOS runtime) which resolved the app crashes for us.

Good luck!

Related