Tôi cần lưu trữ dữ liệu trong bộ nhớ cục bộ bằng cách sử dụng AsyncStorage từ mã JS.Truy cập AsyncStorage từ mã gốc
Tôi muốn biết nếu có cách truy cập dữ liệu được lưu trữ từ AsyncStorage từ mã gốc (Objective-C hoặc Java).
Cảm ơn!
Tôi cần lưu trữ dữ liệu trong bộ nhớ cục bộ bằng cách sử dụng AsyncStorage từ mã JS.Truy cập AsyncStorage từ mã gốc
Tôi muốn biết nếu có cách truy cập dữ liệu được lưu trữ từ AsyncStorage từ mã gốc (Objective-C hoặc Java).
Cảm ơn!
Nếu bạn nhập RCTAsyncLocalStorage.h
, bạn có thể gọi _getValueForKey
: https://github.com/facebook/react-native/blob/master/React/Modules/RCTAsyncLocalStorage.m#L266
Vì '_getValueForKey' là một phương pháp riêng, tôi đã cố gắng gọi: '[asyncLocalStorage multiGet: @ [@" USER_MESSENGER_SESSION "] gọi lại:^(phản hồi NSArray *) { nếu ([số phản hồi]> 0) { NSDictionary * userMessengerSession = response [0 ]; nếu (userMessengerSession) { [[SinchClientManager sharedManager] .sinchService logInUserWithId: userMessengerSession [@ "user"] [@ "id"]]; } } }]; 'Nhưng tôi đã có SIGABRT –
@JeanLebrument bạn có khắc phục được sự cố không? – draw
@draw Tôi đã nhận được nó như thế này, nhưng nó là hacky lúc tốt nhất: '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) { } }); ' –
Nếu bạn/ai vẫn đang tìm kiếm này. Kiểm tra câu trả lời của tôi ở đây: https://stackoverflow.com/questions/37164887/can-i-access-data-stored-in-react-natives-asyncstorage-from-java-layer/47551790#47551790 –