从原生代码中访问AsyncStorage

10

我需要使用JS代码中的AsyncStorage将数据持久化到本地存储中。

我想知道是否有一种方法可以从原生代码(Objective-C或Java)访问从AsyncStorage存储的数据。

谢谢!


如果你/任何人仍在寻找这个问题的答案,请查看我的回答: https://dev59.com/PFoU5IYBdhLWcg3wu4ri#47551790 - Muhammad Riyaz
1个回答

2

因为 _getValueForKey 是一个私有方法,所以我尝试调用:[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"]]; } } }]; 但是我遇到了 SIGABRT。 - Jean Lebrument
@draw 我已经让它像这样运行了,但最好还是有点hacky:`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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接