iOS:fix crash for command view

This commit is contained in:
pengfei.zhou 2020-03-25 19:32:01 +08:00 committed by osborn
parent 673a8d0611
commit 61c74e1c25

View File

@ -95,34 +95,32 @@ - (void)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
invocation.selector = selector; invocation.selector = selector;
invocation.target = target; invocation.target = target;
__weak __typeof__(self) _self = self; void *retValue;
dispatch_block_t block = ^() { @try {
__strong __typeof__(_self) self = _self; NSMutableArray *tempArray = [NSMutableArray new];
@try {
for (NSUInteger idx = 2; idx < methodSignature.numberOfArguments; idx++) { for (NSUInteger idx = 2; idx < methodSignature.numberOfArguments; idx++) {
if (idx - 2 > [array count]) { if (idx - 2 > [array count]) {
break; break;
}
id param = [self createParamWithMethodName:array[idx - 2] promise:promise argument:argument];
[invocation setArgument:&param atIndex:idx];
} }
[invocation invoke]; id param = [self createParamWithMethodName:array[idx - 2] promise:promise argument:argument];
} @catch (NSException *exception) { if (param) {
DoricLog(@"CallNative Error:%@", exception.reason); [tempArray addObject:param];
[self.doricContext.driver.registry onException:exception inContext:self.doricContext]; }
[invocation setArgument:&param atIndex:idx];
} }
}; [invocation invoke];
dispatch_async(dispatch_get_main_queue(), ^{ } @catch (NSException *exception) {
void *retValue; DoricLog(@"CallNative Error:%@", exception.reason);
block(); [self.doricContext.driver.registry onException:exception inContext:self.doricContext];
const char *retType = methodSignature.methodReturnType; }
if (!strcmp(retType, @encode(void))) { const char *retType = methodSignature.methodReturnType;
} else { if (!strcmp(retType, @encode(void))) {
[invocation getReturnValue:&retValue]; } else {
id returnValue = (__bridge id) retValue; [invocation getReturnValue:&retValue];
[promise resolve:returnValue]; id returnValue = (__bridge id) retValue;
} [promise resolve:returnValue];
}); }
} }
break; break;
} }