繁体   English   中英

如何处理iOS4.0以上版本的iPhone模拟器NSInvocation问题

[英]How to handle iPhone Simulator NSInvocation issue for iOS4.0+

对于iPhone Simulator iOS4.0 +,NSInvocation无法很好地处理异常。 我遇到了使用objc_msgSend的解决方法 当我尝试将其作为objc_msgSend(target_,[invocation selector])进行以下调用时,在createResponseFromInvocation()下挂起了[invocation invoke]注释。 我尝试了不同的调用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;
}

我找到了一个解决方案,方法是完全删除NSInvocation并在选择器上调用objc_msgSend。 该解决方法有助于解决所有NSInvocation异常处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM