While migrating from native iOS (Objective-C) development to react native development, how do we keep our existing user 'signed in' and make the transition seamless for the users when they update the app from the app store.
For this to happen...
The question is:
We have recently had the same use-case in one of our apps and decided to do the following:
Read from NSUserDictionary just like normally (fetch all the elements) and pass them to RCTRootView
NSDictionary *userSettings = @{}; // fetch them here
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"XYZ"
initialProperties:userSettings
launchOptions:launchOptions];
Assuming your userSettings dictionary contains e.g. accessToken property, you should be able to just access this.props.accessToken from within your root React component (the one you pass to AppRegistry.registerComponent).
Next, you can either check if values have been already persisted to AsyncStorage (or is there any other copy of userSettings that you should use) and if not - persist the current values.
Another alternative is to use Settings module that is available in React Native that allows you to access NSUserDefaults. It has .get() and .set() methods, so technically it should be possible to use it.
Note that userSettings passed through initialProperties will not update until you re-run the app from within the Xcode.
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