FCM Notifications fail to arrive (on device) when internet is slightly disturbed - Flutter

4 days ago 5
ARTICLE AD BOX

I am facing an issue using FCM in my flutter application while receiving notifications.

The issue is related to receiving notifications on client end, when the internet is slightly disturbed from the backhaul (1 or 2 second), after that the client fails to receive push notification from FCM until a proper network disconnection and reconnection is not performed.

To reproduce, I've connected the client (mobile having app and FCM) to a Wi-Fi hotspot (using mobile data) and send the notifications. It's working as expected. Now, if I turn the mobile data (not the wifi hotspot) off and on again (with a very short duration, 1 or 2 sec). After that, the mobile app failed to receive messages (Push Notifications) until or unless I've turned off the Hotspot and the Wi-Fi on the client device got connected to some other network (a proper network disconnection)

For confirmation, I've tested the same behavior on Microsoft Teams, and it's having the same issue. But surprisingly, WhatsApp does not have this issue (maybe they're handling that in some other way).

For clarity, I'm facing this issue on iOS and Android devices. To fix that issue, on iOS I found a way to re-register for remote notifications.

// Unregister from APNs UIApplication.shared.unregisterForRemoteNotifications() // Re-register UIApplication.shared.registerForRemoteNotifications()

Since my App is built on flutter, I've utilized method channels to execute the native (Swift) code from flutter on internet reconnection. Even I've tried doing this manually (through a testing button from my flutter app) and as soon as I do this (the re-registration), the Push Notifications starts working again as normal.

So, what's happing (as far as I've understand), as soon as the internet slightly disturbed, the FCM does not reconnect to the internet again and the connection goes stale.

I'm not sure if this (workaround for iOS) is the correct or recommended way to fix that issue.

Also, I haven't found anything related to android to fix that issue. However, I've observed one thing on android (Google Pixel), by dialing a code *#*#426#*#* it displays an FCM Diagnostics Tool where we can visualize the FCM connection is stablished or not. So, I've monitored the FCM behavior using the mechanism I've described above, and the FCM status was Connected for more than 5 minutes (I haven't gone further). And at that time, there was no internet connection on the backhaul (mobile data was turned off) only the hotspot was connected.

I'll be doing some more research using some other applications to visualize if they are having the same issue or to find a way to reconnect on android (manually).

If anybody can provide any assistance or feedback, would love to have that!

Thanks

Read Entire Article