AFHTTPRequestOperation setAuthenticationAgainstProtectionSpaceBlock无法识别的选择器错误:

时间:2013-06-28 11:02:54

标签: objective-c afnetworking

我正在尝试在IOS中运行以下代码。

AFHTTPRequestOperation *requestOperation = [self.httpClient HTTPRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url.text]]
                                         success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                           NSLog(@"reply data = %@", [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding]);
                                         }
                                         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                           NSLog(@"%@", error);
                                         }];
[requestOperation setAuthenticationAgainstProtectionSpaceBlock:^BOOL(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace) {
  return YES;
}];

然后我得到这样的错误:

  

- [AFHTTPRequestOperation setAuthenticationAgainstProtectionSpaceBlock:]:无法识别的选择器发送到实例0x75a81f0

据我所知,我传递的块具有正确的返回类型和参数。我在这做错了什么?

1 个答案:

答案 0 :(得分:5)

AFURLRequestOperation有条件地使用某些可用的委托回调方法进行编译,具体取决于是否定义了_AFNETWORKING_PIN_SSL_CERTIFICATES_

如果是(从CocoaPods安装时是默认设置),setWillSendRequestForAuthenticationChallengeBlock:将可用。否则setAuthenticationAgainstProtectionSpaceBlock:setAuthenticationChallengeBlock:将可用。

setWillSendRequestForAuthenticationChallengeBlock对应connection:willSendRequest:forAuthenticationChallenge:,即the preferred delegate method to handle challenges