簡體   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