I need to persist data in local storage using AsyncStorage from JS code.
I would like to know if there is a way to access data stored from AsyncStorage from native code (Objective-C or Java).
Thanks!
I need to persist data in local storage using AsyncStorage from JS code.
I would like to know if there is a way to access data stored from AsyncStorage from native code (Objective-C or Java).
Thanks!
If you import RCTAsyncLocalStorage.h
, you can call _getValueForKey
: https://github.com/facebook/react-native/blob/master/React/Modules/RCTAsyncLocalStorage.m#L266
_getValueForKey
is a private method, I tried to call: [asyncLocalStorage multiGet:@[@"USER_MESSENGER_SESSION"] callback:^(NSArray *response){ if ([response count] > 0) { NSDictionary *userMessengerSession = response[0]; if (userMessengerSession) { [[SinchClientManager sharedManager].sinchService logInUserWithId:userMessengerSession[@"user"][@"id"]]; } } }];
But I had a SIGABRT
– Jean Lebrument
Dec 31 '15 at 9:57
RCTAsyncLocalStorage *asyncLocalStorage = [[RCTAsyncLocalStorage alloc] init]; dispatch_async([asyncLocalStorage methodQueue], ^{ [asyncLocalStorage _ensureSetup]; NSDictionary *err = [[NSDictionary alloc] init]; NSString* val = [asyncLocalStorage _getValueForKey:@"@foobar" errorOut:&err]; if (err) { } });
– Felix Schlitter
Jan 5 '17 at 3:08