[英]How to handle iPhone Simulator NSInvocation issue for iOS4.0+
For iPhone Simulator iOS4.0+, NSInvocation doesn't handle exceptions well. 对于iPhone Simulator iOS4.0 +,NSInvocation无法很好地处理异常。 I came across a workaround to use objc_msgSend.
我遇到了使用objc_msgSend的解决方法 。 When I tried it for the below invocation as objc_msgSend(target_, [invocation selector]) and commenting out [invocation invoke] under createResponseFromInvocation() hangs.
当我尝试将其作为objc_msgSend(target_,[invocation selector])进行以下调用时,在createResponseFromInvocation()下挂起了[invocation invoke]注释。 I tried different ways of calling obj_msgSend and didn't work.
我尝试了不同的调用obj_msgSend的方式,但没有成功。
- (NSInvocation *)createInvocationWithSelector:(SEL)selector
signature:(NSMethodSignature *)method
arguments:(NSDictionary *)arguments {
NSInvocation *invocation
= [NSInvocation invocationWithMethodSignature:method];
[invocation setSelector:selector];
[invocation setTarget:target_];
if (arguments != nil) {
if ([method numberOfArguments] > 2) {
[invocation setArgument:&arguments atIndex:2];
}
}
return invocation;
}
// Invoke the given invocation and create a response from it.
- (WDResponse *)createResponseFromInvocation:(NSInvocation *)invocation {
WDResponse *response;
@try {
[invocation invoke];
if ([[invocation methodSignature] methodReturnLength] == 0) {
response = [WDResponse responseWithValue:nil];
} else {
id result;
[invocation getReturnValue:&result];
response = [WDResponse responseWithValue:result];
}
}
@catch (NSException * e) {
NSLog(@"Method invocation error: %@", e);
response = [WDResponse responseWithError:e];
}
return response;
}
I found a solution by removing NSInvocation completely and calling objc_msgSend on the selector. 我找到了一个解决方案,方法是完全删除NSInvocation并在选择器上调用objc_msgSend。 This workaround helped in resolving all NSInvocation Exception handling.
该解决方法有助于解决所有NSInvocation异常处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.