Как справиться с проблемой iPhone Simulator NSInvocation для iOS4.0 + - PullRequest
0 голосов
/ 13 октября 2010

Для iPhone Simulator iOS4.0 + NSInvocation плохо обрабатывает исключения.Я наткнулся на обходной путь , чтобы использовать objc_msgSend.Когда я попробовал его для вызова ниже, как objc_msgSend (target_, [invocation selector]) и комментирование [invocation invoke] под createResponseFromInvocation () зависаетЯ пробовал разные способы вызова 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;
}

1 Ответ

0 голосов
/ 13 октября 2010

Я нашел решение, полностью удалив NSInvocation и вызвав objc_msgSend для селектора.Этот обходной путь помог разрешить всю обработку исключений NSInvocation.

...