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,15 +95,18 @@ - (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 = ^() {
__strong __typeof__(_self) self = _self;
@try { @try {
NSMutableArray *tempArray = [NSMutableArray new];
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]; id param = [self createParamWithMethodName:array[idx - 2] promise:promise argument:argument];
if (param) {
[tempArray addObject:param];
}
[invocation setArgument:&param atIndex:idx]; [invocation setArgument:&param atIndex:idx];
} }
[invocation invoke]; [invocation invoke];
@ -111,10 +114,6 @@ - (void)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(
DoricLog(@"CallNative Error:%@", exception.reason); DoricLog(@"CallNative Error:%@", exception.reason);
[self.doricContext.driver.registry onException:exception inContext:self.doricContext]; [self.doricContext.driver.registry onException:exception inContext:self.doricContext];
} }
};
dispatch_async(dispatch_get_main_queue(), ^{
void *retValue;
block();
const char *retType = methodSignature.methodReturnType; const char *retType = methodSignature.methodReturnType;
if (!strcmp(retType, @encode(void))) { if (!strcmp(retType, @encode(void))) {
} else { } else {
@ -122,7 +121,6 @@ - (void)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(
id returnValue = (__bridge id) retValue; id returnValue = (__bridge id) retValue;
[promise resolve:returnValue]; [promise resolve:returnValue];
} }
});
} }
break; break;
} }