I have a React Native App for which I am trying to build an iOS share extension, using Swift. I'd like the share extension to have access to the token set in the React Native app. I have set up an app group, which contains the app and the share extension.
In the app, I am using react-native-default-preference to set UserDefaults.
import DefaultPreference from 'react-native-default-preference'
DefaultPreference.set('authToken', token)
In my share extension view controller, I have
if let userDefaults = UserDefaults(suiteName: "group.myGroup.myApp") {
let value1 = userDefaults.string(forKey: "authToken")
print("retrieved token value\(value1)")
}
This always prints out nil
. I'm basically new to Swift and Xcode so I have no idea if what I am doing should work. I'm also not certain if I should have the app running in Xcode or the share extension running, so I keep switching back and forth between the two, but it doesn't work either way.
Is there something that I am missing, or can anyone offer an alternative solution? Many thanks in advance!
I needed to call DefaultPreference.setName('group.myGroup.myApp')
in my RN project. Thanks to kevinresol, who developed the library, for the solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With