istornz / flutter_live_activities

A Flutter plugin to use iOS 16.1+ Live Activities ⛹ī¸ & iPhone Dynamic Island 🏝ī¸ features
https://dimitridessus.fr/
MIT License
175 stars 54 forks source link

Add prefix for shared preference usage #54

Closed Clon1998 closed 11 months ago

Clon1998 commented 11 months ago

Based on my comment in #19, it is not possible to use multiple live activities simultaneously due to the use of UserDefaults to transfer data from Flutter to the live activity. However, to resolve this issue, I added a prefix to all of the stored values in UserDefaults using the ID set via LiveActivitiesAppAttributes. This modification enables the use of multiple live activities without any conflict.

For now, this is just a discussion. I was able to successfully test my implementation for local creations and updates but not for remote updates yet.

istornz commented 11 months ago

Thanks for your PR @Clon1998, I think creating a prefix is the good idea.

An another fix will be to revert back usage of dynamic LiveActivities attributes but I think UserDefaults is the better way to transmit typed data to Swift code (discussion here).

I will test your PR ASAP 👍

Clon1998 commented 11 months ago

Thanks for your PR @Clon1998, I think creating a prefix is the good idea.

An another fix will be to revert back usage of dynamic LiveActivities attributes but I think UserDefaults is the better way to transmit typed data to Swift code (discussion here).

I will test your PR ASAP 👍

I thought about the dynamic attributes. But this might break the remote updates for other devs. This change already is a breaking change as it will require all users to include the prefix before using any key.

Clon1998 commented 11 months ago

Just tested APNs/Remote updates. They now work as expected for multiple live activities :)