istornz / flutter_live_activities

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

`getAllActivitiesIds() `method does not return active live activities after app quit and relaunch #42

Closed SethuSenthil closed 1 year ago

SethuSenthil commented 1 year ago

Issue Description: When the user quits the app manually or if the app is forcefully quit by the iOS system and then relaunched, the getAllActivitiesIds() method fails to return the active live activities that are currently ongoing. This issue poses a problem as it prevents the app from accurately retrieving the list of active live activities after a relaunch.

Steps to Reproduce:

  1. Launch the app and start some live activities.
  2. Manually quit the app or let iOS force quit it.
  3. Relaunch the app.
  4. Call the getAllActivitiesIds() method to retrieve the list of active live activities.

Expected Behavior: The getAllActivitiesIds() method should return the correct and up-to-date list of active live activities, even after the app has been quit and relaunched.

Actual Behavior: The getAllActivitiesIds() method fails to return the active live activities that are currently live after the app has been quit and relaunched. It appears that the method does not recognize the ongoing activities as active, resulting in an inaccurate list.

Additional Information:

Possible Solution: One potential solution to this issue is to implement a mechanism that persists the state of active live activities when the app is about to be quit or force quit. Upon relaunch, the app can then retrieve the persisted state and correctly identify the ongoing activities as active. Additionally, thorough testing and debugging should be performed to identify any underlying issues in the getAllActivitiesIds() method or its dependencies.

SethuSenthil commented 1 year ago

Upon investigating the issue, I would like to close the issue with the fact that this behavior is actually a known limitation as documented by the package. The package's documentation states that updating a live activity after the app has been quit or killed in the background requires the use of push notifications, which involves setting up a server.

However, based on your specific use case, there is an alternative approach you can consider. You can manually check if the live activity is still active when the app relaunches. If it is no longer active, you can remove all live notifications associated with that activity. Then, you can create a new notification with the modified data to reflect the changes made since the previous run.

Since the library utilizes persistent storage (User Defaults) to share data between the Live Activity and the Flutter application, the previous data is saved. This allows you to pass in only the data that has changed since the previous run, reducing the amount of unnecessary data processing.

I understand that this workaround may not be ideal for all situations, but there is no other way at the moment cause Apple.

kvenn commented 10 months ago

Are you saying that getAllActivitiesIds shouldn't return any id's after the app is force terminated?

There isn't anything in the docs about that. So just want to make sure.

Right now, because this isn't working, I'm ending all activities every time my app starts and recreating them. But I'd love to not do that.