0

我正在尝试在 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

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

4

1 回答 1

5

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

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

setWillSendRequestForAuthenticationChallengeBlock对应connection:willSendRequest:forAuthenticationChallenge:,这是处理挑战的首选委托方法

于 2013-06-28T17:46:39.440 回答