-
-
Save umhan35/fd0e0c9efab7b92380868e4d51c46808 to your computer and use it in GitHub Desktop.
access asyncLocalStorage in objective-c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add libReact.a | |
// import | |
#import "RCTAsyncLocalStorage.h" | |
// code | |
RCTAsyncLocalStorage *asyncLocalStorage = [[RCTAsyncLocalStorage alloc] init]; | |
dispatch_async([asyncLocalStorage methodQueue], ^{ | |
[asyncLocalStorage multiGetKeys:@[@"widget_city"] callback:^(NSArray *response){ | |
NSLog(@"%@", response); | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self populateViewForCity]; | |
}); | |
}]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)multiGetKeys:(NSArray<NSString *> *)keys callback:(RCTResponseSenderBlock)callback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)multiGetKeys:(NSArray<NSString *> *)keys | |
callback:(RCTResponseSenderBlock)callback | |
{ | |
NSDictionary *errorOut = [self _ensureSetup]; | |
if (errorOut) { | |
callback(@[@[errorOut], (id)kCFNull]); | |
return; | |
} | |
NSMutableArray<NSDictionary *> *errors; | |
NSMutableArray<NSArray<NSString *> *> *result = [[NSMutableArray alloc] initWithCapacity:keys.count]; | |
for (NSString *key in keys) { | |
id keyError; | |
id value = [self _getValueForKey:key errorOut:&keyError]; | |
[result addObject:@[key, RCTNullIfNil(value)]]; | |
RCTAppendError(keyError, &errors); | |
} | |
callback(@[RCTNullIfNil(errors), result]); | |
} | |
#pragma mark - Exported JS Functions | |
RCT_EXPORT_METHOD(multiGet:(NSArray<NSString *> *)keys | |
callback:(RCTResponseSenderBlock)callback) | |
{ | |
[self multiGetKeys:keys callback:callback]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment