istornz / flutter_live_activities

A Flutter plugin to use iOS 16.1+ Live Activities ⛹️ & iPhone Dynamic Island 🏝️ features
https://dimitridessus.fr/
MIT License
163 stars 49 forks source link

Live activity not updated in background #24

Closed ggirotto closed 1 year ago

ggirotto commented 1 year ago

Hey there, first of all congrats for this plugin. Very easy and intuitive to use. My question relates with background updates, but I'm not sure if this relates with the package itself or with Flutter. We are currently updating our live activities from a broadcast connection with our server-side. I noticed that when the app goes to background, our live activity stop being updated, but I couldn't understand why. Considering that the code that updates the live activity is in the Flutter-side, how the background update is being handled?

jolamar commented 1 year ago

Replying from my phone so brief. When you create activity Flutter will listen for a push token to be created. That should be sent and stored to your backend and send along with your payload to update the live activity. Are you getting this far? It sounds like it’s getting sent to the background and no longer updating (the live activity should work and update without your app even being opened). The only unknown is there are push token updates and Apple has not documented when those occur. So we also need to listen for token updates and send those to the backend. But what if the app isn’t open or is in background. So what I would be curious to see when your live activity stops updating is to send a Postman request with the original push token and a new payload/time stamp and see if it works or gives any errors.

jolamar commented 1 year ago

I should mention if you are using the Flutter method updateActivity() that will no longer work if the app goes in the background or if closed that’s why push token method is better for updating the live activity.

ggirotto commented 1 year ago

Thanks for the clarification @jolamar. As far as I could understand, the lifecycle would be something like:

So the app only responsibility is to create the activity and send this token to the server. Further updates must be handled directly from there through push notifications

jolamar commented 1 year ago

That’s all correct. You should also listen for live activity dismisses (user dismisses it) and send that to the backend to prevent further pushes. But of course this won’t work if the app is not open but it’s good cleanup and will probably catch most of the cases.

ggirotto commented 1 year ago

Great, thanks for the clarification @jolamar !