0

I was using the fcm push notification to get the real time updates(the update in my device,ie. whether the lights are manually off or on in the device etc..)get happen in the mobile application.But the push notifications are sometimes found missing and my app started showing sync issues to the real time. It could be very helpfull for me if anyone can suggest a better method to implement this process. I had heard about enabling a socket connection but dont know much about that. Thankyou

Diablo
  • 1
  • 1

1 Answers1

-1

FCM cloud messaging is not meant to be real-time because of things like being offline or the device having notifications turned off. But it does keep trying until the message is delivered. (Like when the network connectivity re-establishes).

Here are some ideas:

1 Delivery Receipts

You might try to check that all FCM messages are received, but this may be platform dependent.

Firebase Cloud Messaging - Identify delivery status for a particular push notification message

This might uncover that not all messages are being received, which could be an issue with how you are using firebase. Or, it might be that the messages are being delivered but not captured correctly, which might be in your code.

2 Sockets, but only while your app is open.

Sockets are great, but require being online. As long as the socket is open, you can be sure that the messages are sent.

But sockets probably require your app to be open. There are background sockets, but I don't know how good support is for flutter. See https://blog.codemagic.io/flutter-ui-socket/

3 Use cloud-firestore or realtime database, then sync up next time the app opens.

Your update messages can be cached or logged in something like cloud_firestore. And then, when you login, the datastore can be synced to your device.

If you need things to run in the background, then maybe look at this question: How to create a Flutter background service that works also when app closed

chongman
  • 2,447
  • 4
  • 21
  • 23
  • Thank you very much, i am thinking that the socket connection can be the best method suitable for my process. – Diablo Dec 08 '21 at 04:44