dpa99c / cordova-plugin-firebasex

Cordova plugin for Google Firebase
MIT License
570 stars 459 forks source link

iOS onMessageReceived not working #467

Closed trackmyapp closed 3 years ago

trackmyapp commented 3 years ago

Bug report

CHECKLIST

Current behavior: Foreground and background notifications do not work on iOS. onMessageReceived() is not executed and no exception or error message is printed in Xcode. I've used the example project by only changing the package ID and overwriting the GoogleService-Info.plist file. After installing the example project the user gets asked to grant permission, the button "Get FCM token" works as expected.

What I tried and didn't work?

To send the notification I'm using postman with the following body:

{ "to": "device-Token-ID", "notification": { "body": "Notification body", "title": "New Message!" }, "data": { "notification_foreground": "true" } }

The notifications worked until 15.07.2020, but now it does not.

Expected behavior: onMessageReceived() should be executed, when receiving a push notification

Steps to reproduce: Environment information

Runtime issue

iOS build issue:

Related code:

FirebasePlugin.onMessageReceived(function(message) {
        console.log("test message received");
        try{
            console.log("onMessageReceived");
            console.dir(message);
            if(message.messageType === "notification"){
                handleNotificationMessage(message);
            }else{
                handleDataMessage(message);
            }
        }catch(e){
            logError("Exception in onMessageReceived callback: "+e.message);
        }

    }, function(error) {
        logError("Failed receiving FirebasePlugin message", error);
    });



Other information: I'm using Ionic 4.

Any help would be appreciated.

dpa99c commented 3 years ago

Try using the FCM v1 API client in the example project to send messages using the Firebase Admin SDK to rule out any possible issue with your message structure.

If no notification is received on iOS when the app is in the background/not running then the problem is then likely to be your APNS configuration since no app code (including the plugin) is executed when a system notification is displayed until such time as the user taps it to trigger an app launch.

trackmyapp commented 3 years ago

Thank you for the fast reply. I tried it again today without changing any code and now I'm receiving push notifications again in the example project. I close the issue.

trung-pham commented 3 years ago

@trackmyapp I was able to receive the notification but not able to catch any callback from message events. Are you able to catch message events? Btw, i'm using cordova.

trackmyapp commented 3 years ago

@trackmyapp I was able to receive the notification but not able to catch any callback from message events. Are you able to catch message events? Btw, i'm using cordova.

Yes, I'm able to receive notifications and also catch the onMessageReceived callback. PS: Sorry for the late reply. Hope it still helps.

asimon91 commented 2 years ago

Hello there @dpa99c ,

I'm also facing issues with onMessageReceived in iOS. With Android is working flawless.

My current cordova-firebasex-plugin version is 13.0.0, and I don't have the cordova local notifications plugin installed in my project. I'm using instead capacitor's local notifications plugin.

I've also tried with latest cordova local notifications beta plugin that's supposed to work fine paired with this one, but I'm getting the same behavior.

I've tried to add breakpoints to the main notification handling functions in AppDelegate+FirebasePlugin.m file, but it does not stop in any one.

I've also tried to make a new project from scratch with just firebasex and capacitor local notifications plugins, but it's still failing to display notificacions while iOS app is in foreground. The "onMessageReceived" method is never being called, I don't even have any error or warning in xcode log.

Background notifications are working fine, so any APNs problem can be discarded. The problem is just with foreground ones. OAUTH 2.0 Firebase notifications are also not working.

What could I have been missing?

SamEBM commented 2 years ago

Hello there @dpa99c ,

I'm also facing issues with onMessageReceived in iOS. With Android is working flawless.

My current cordova-firebasex-plugin version is 13.0.0, and I don't have the cordova local notifications plugin installed in my project. I'm using instead capacitor's local notifications plugin.

I've also tried with latest cordova local notifications beta plugin that's supposed to work fine paired with this one, but I'm getting the same behavior.

I've tried to add breakpoints to the main notification handling functions in AppDelegate+FirebasePlugin.m file, but it does not stop in any one.

I've also tried to make a new project from scratch with just firebasex and capacitor local notifications plugins, but it's still failing to display notificacions while iOS app is in foreground. The "onMessageReceived" method is never being called, I don't even have any error or warning in xcode log.

Background notifications are working fine, so any APNs problem can be discarded. The problem is just with foreground ones. OAUTH 2.0 Firebase notifications are also not working.

What could I have been missing?

Hi @asimon91 Were you able to solve it? I'm facing the exact same issue with an Ionic / Cordova project. Everything works fine on Android, but only foreground notifications never make it to iOS, onMessageReceived callback don't get executed.

I'm using both cordova plugins, Firebase X and Local Notifications, is there any issue between those two?

Any help will be appreciated.