I want to know how to get shared_preferences in iOS share extension (swift code).
I use 'shared_preferences' to store session date in this code.
SharedPreferences.getInstance().setString("session", "session_sata")
And, I tried to get 'SharedPreferences' iOS in share extension (swift) by using UserDefaults
like this code .
UserDefaults.standard.persistentDomain(forName: "")
UserDefaults.init(suiteName: "")
However, I couldn't get session date in swift code, even more I couldn't find a key of "flutter.session".
Does anyone know how to get shared_preferences in iOS share extension?
To be able to share data between an iOS host app and its app extension you need to:
App Group
capability/entitlement to the app and the extensionsuiteName
:UserDefaults(suiteName: ${appGroupIdentifier})
And unfortunately this is not possible with the current state of the SharedPreferences pub. Here is the GitHub issue addressing this.
A possible solution to your problem is to try out this pub, which appears to be created to handle this use case: https://pub.dev/packages/shared_preference_app_group