EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 444 forks source link

Firebase cloud messaging ios device not working #1534

Closed aldoabazi closed 4 years ago

aldoabazi commented 4 years ago

Hi, first of all thank you for the amazing work with this plugin. I am using fcm for an app in ios and android built with nativescript angular. It works perfectly on android(emulator and device) but in ios only works in simulator. Here is my code:

app.component.ts

constructor() {
    LocalNotifications.LocalNotifications.addOnMessageReceivedCallback(notificationData => {
        console.log("Notification received: " + JSON.stringify(notificationData));
    });
}

ngOnInit(): void {
    firebase.init({
        showNotifications: true,
        showNotificationsWhenInForeground: true,

        onPushTokenReceivedCallback: (token) => {
            console.log('[Firebase] onPushTokenReceivedCallback:', { token });
            if(token !== applicationSettings.getString('firebaseToken')) {
                applicationSettings.setString('firebaseToken', token);
            }
        },

        onMessageReceivedCallback: (message: firebase.Message) => {
          console.log('[Firebase] onMessageReceivedCallback:', message );
            LocalNotifications.LocalNotifications.schedule(
                [{
                  thumbnail: true,
                  title: message.title,
                  body: message.body,
                  forceShowWhenInForeground: true,
                }])
                .then(() => {
                  console.log('alert');
                })
                .catch(error => console.log("doScheduleId5WithInput error: " + error));
        }
    })
        .then(() => {
          console.log('[Firebase] Initialized');
        })
        .catch(error => {
          console.log('[Firebase] Initialize', { error });
        });
}

As you can see i am using local notifications plugin to display notifications. I think i made all the steps needed to make this work but still no changes. Is there any reason why it works on simulator but not in a real device? simulator iphone 11 pro, real device iphone XS max

dereekb commented 4 years ago

Which part is not working, that you are not receiving remote notifications on real devices?

I recall initially running into the same issue; double check that you did this part properly:

https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md#copy-the-entitlements-file

Another thing I had messed up initially was enabling "in app messaging" instead of enabling "messaging", but if it is working in the simulator I don't think you messed this part up.You can double check it regardless in your firebase.nativescript.json file, as well as checking if "pod Firebase/Messaging" exists in the Pod file.

It might also be helpful to post what you're expecting to happen. As far as I understand it you're using the local notifications plugin to display notifications, which doesn't require the use of the firebase notifications.

Are you triggering a remote notification from the Firebase console?

aldoabazi commented 4 years ago

@dereekb thnx for your reply. In fact the problem was that i uploaded my .p8 file(generated from another apple account) to firebase but my app is registered in another apple account. So the team id of my app build didn't match the team id which .p8 file was uploaded with. In simulator it work because it doesn't need the .p8 file but in a real device it does.So i generated another .p8 file from the account my app is registered and everything works perfect.