iOS:use safe method to prevent unexpected exception

This commit is contained in:
pengfeizhou
2021-02-01 15:31:24 +08:00
committed by osborn
parent 6bf38bd290
commit 5a12a770fd
11 changed files with 125 additions and 65 deletions

View File

@@ -22,7 +22,9 @@
@implementation DoricNavigatorPlugin
- (void)push:(NSDictionary *)params {
dispatch_async(dispatch_get_main_queue(), ^{
__weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
BOOL animated = YES;
NSString *source = params[@"source"];
NSString *alias = source;
@@ -37,21 +39,23 @@ - (void)push:(NSDictionary *)params {
}
}
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
});
}];
}
- (void)pop:(NSDictionary *)params {
dispatch_async(dispatch_get_main_queue(), ^{
__weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
BOOL animated = YES;
if (params[@"animated"]) {
animated = [params[@"animated"] boolValue];
}
[self.doricContext.navigator doric_navigator_pop:animated];
});
}];
}
- (void)openUrl:(NSString *)urlString withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{
[self.doricContext dispatchToMainQueue:^{
NSURL *url = [NSURL URLWithString:urlString];
[UIApplication.sharedApplication openURL:url options:@{} completionHandler:^(BOOL success) {
if (success) {
@@ -60,6 +64,6 @@ - (void)openUrl:(NSString *)urlString withPromise:(DoricPromise *)promise {
[promise reject:@"Cannot open"];
}
}];
});
}];
}
@end