fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
624 stars 991 forks source link

iOS, SOMETIMES receiving background notifications #634

Closed aml25 closed 4 years ago

aml25 commented 4 years ago

I'm actually using https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated, but they appear to have issues turned off. Since it's a fork I figured I'd post this here.

I'm using Cordova 9.0.0 (cordova-lib@9.0.1) and android 8.1.0 and ios 5.1.1. I'm not using Ionic, just plain Cordova.

Android notifications work fine, background and foreground, but I'm experiencing random behavior on iOS. It appears sometimes notifications (background) work and sometimes they don't. Meaning, one on (physical) device running from XCode will work but then uninstalling the app and re-running will randomly stop working. It will also run on an iPhone but not on an iPad - at the same randomness. It seems to get better if I remove all platforms and the FCM plugin and reinstall, but it's not fullproof.

I'm using the Cloud Messaging interface to send the messages to test devices (via FCM Token) but have also tried with https://cordova-plugin-fcm.appspot.com/ using the payloads outlined in README.md

Here's what I've learned so far. I can predict when background notifications will work when a foreground notification prints this in XCode terminal:

2020-03-23 12:03:00.823527-0500 Moments[8227:2033892] Message ID 1: ##########
2020-03-23 12:03:00.823849-0500 Moments[8227:2033892] {
    aps =     {
        alert =         {
            body = "Have you done something that's made your life better today?";
            title = "Daily moment reminder";
        };
        sound = default;
    };
    "click_action" = "FCM_PLUGIN_ACTIVITY";
    "gcm.message_id" = ##########;
    "gcm.n.e" = 1;
    "gcm.notification.sound2" = default;
    "google.c.a.c_id" = ##########;
    "google.c.a.c_l" = dailyReminders;
    "google.c.a.e" = 1;
    "google.c.a.ts" = ##########;
    "google.c.a.udt" = 0;
    "google.c.sender.id" = ##########;
}
2020-03-23 12:03:00.823997-0500 Moments[8227:2033892] stringByEvaluatingJavaScriptFromString FCMPlugin.onNotificationReceived({"google.c.sender.id":"##########","google.c.a.e":"1","gcm.notification.sound2":"default","aps":{"alert":{"title":"Daily moment reminder","body":"Have you done something that's made your life better today?"},"sound":"default"},"google.c.a.c_l":"dailyReminders","gcm.n.e":"1","google.c.a.c_id":"##########","google.c.a.udt":"0","gcm.message_id":"##########","google.c.a.ts":"##########","click_action":"FCM_PLUGIN_ACTIVITY"});
2020-03-23 12:03:00.827075-0500 Moments[8227:2033892] Received push notification
2020-03-23 12:03:00.827221-0500 Moments[8227:2033892] {"google.c.sender.id":"##########","google.c.a.e":"1","gcm.notification.sound2":"default","aps":{"alert":{"title":"Daily moment reminder","body":"Have you done something that's made your life better today?"},"sound":"default"},"google.c.a.c_l":"dailyReminders","gcm.n.e":"1","google.c.a.c_id":"##########","google.c.a.udt":"0","gcm.message_id":"##########","google.c.a.ts":"##########","click_action":"FCM_PLUGIN_ACTIVITY"}

I can predict background notifications will not work when XCode terminal prints this from a foreground notification

2020-03-23 11:49:10.268186-0500 Moments[293:6446] 6.3.0 - [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented

^ The above 2 printouts are literally from the same device, exact same code, but going from running from XCode to device, then uninstalling from device, then running again to the same device all within a couple minutes.

This randomness is consistent from day to day and I can't seem to get it stable. I realize there's a lot of info out there on this issue but I haven't come across these 2 different printouts from XCode so thought it either might help troubleshoot or someone has seen this before and has an idea how to fix it.

aml25 commented 4 years ago

I will report back if I see any other issues, but I'm closing this for now as I think I resolved it. Here's what I did:

I edited a ton of other stuff before getting to this point so if you still can't get it working let me know, I might have tried something you didn't. Like, adding this to config.xml in the ios platform section:

<config-file target="*-Info.plist" parent="UIBackgroundModes">
            <array>
                <string>remote-notification</string>
            </array>
        </config-file>