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;
}
4

1 に答える 1

0

NSInvocation を完全に削除し、セレクターで objc_msgSend を呼び出すことで解決策を見つけました。この回避策は、すべての NSInvocation Exception 処理の解決に役立ちました。

于 2010-10-13T18:25:36.040 に答える