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

Multiple notifications support broke the library usage for single notifications #69

Closed ggirotto closed 8 months ago

ggirotto commented 8 months ago

The new multiple notifications addition (https://pub.dev/packages/live_activities#multiple-notifications-) broke the app for single notification usage. The step of getting the notification from user defaults now fail if the key prefix implementation is not added.

Clon1998 commented 8 months ago

Hey, This was something I mentioned to @istornz in my PR that added multi notification support. You will need to make use of the prefix even for single notifications now. I am open to other solutions that would allow both single and multiple life activities at the same time without a clash in the sharedDefault.

The project's readme also includes a section regarding the new usage of the sharedDefaults.

image
Clon1998 commented 8 months ago

Tl; DR;

To migrate from 1.8.x -> 1.9.x:

  1. Add the new extension to the end of your file or as a new file you want to import:

    extension LiveActivitiesAppAttributes {
    func prefixedKey(_ key: String) -> String {
    return "\(id)_\(key)"
    }
    }
  2. Replace all access to the sharedDefault with the prefixed version:

ActivityConfiguration(for: LiveActivitiesAppAttributes.self) { context in
   ...
  // old
  let matchName = sharedDefault.string(forKey: "matchName")!

  // new
  let matchName = sharedDefault.string(forKey: context.attributes.prefixedKey("matchName"))!
   ...
istornz commented 8 months ago

Hi @ggirotto ! As @Clon1998 said, now you need to add a prefix even for single notification. I updated README.md file & put the 1.9.0 release as Breaking Changes.

If we found an another solution I will remove the dependence of prefix for single based notification 👍

ggirotto commented 8 months ago

Hey guys,

Sorry, that was my bad. I didn't pay attention to README and CHANGELOG before creating this ticket. The steps are well described there. Thanks for the answers!