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

@@ -26,6 +26,7 @@
#import "DoricConstant.h"
#import "DoricExtensions.h"
#import "DoricNativeDriver.h"
#import "DoricUtil.h"
@implementation DoricContext
@@ -115,10 +116,23 @@ - (void)onShow {
- (void)onHidden {
[self callEntity:DORIC_ENTITY_HIDDEN withArgumentsArray:@[]];
}
- (UIViewController *)vc {
if(!_vc) {
if (!_vc) {
return [UIApplication sharedApplication].keyWindow.rootViewController;
}
return _vc;
}
- (void)dispatchToMainQueue:(_Nonnull dispatch_block_t)block {
dispatch_async(dispatch_get_main_queue(), ^{
@try {
block();
} @catch (NSException *exception) {
DoricLog(@"dispatchToMainQueue Error:%@", exception.reason);
[self.driver.registry onException:exception inContext:self];
}
});
}
@end