无法在AFHTTPRequestOperation上调用setWillSendRequestForAuthenticationChallengeBlock:

时间:2013-06-30 18:10:35

标签: objective-c afnetworking

我试图覆盖AFHTTPClient中的-HTTPRequestOperationWithRequest:success:failure:方法,如下面的代码所示:

-(AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
  AFHTTPRequestOperation *requestOperation = [super HTTPRequestOperationWithRequest:urlRequest success:success failure:failure];

  [requestOperation setWillSendRequestForAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {

  }];

  return requestOperation;
}

当我尝试编译它时,我收到以下错误:

  

'AFHTTPRequestOperation'没有可见的@interface声明选择器'setWillSendRequestForAuthenticationChallengeBlock:'

setWillSendRequestForAuthenticationChallengeBlock:方法在AFURLConnectionOperation中定义,但AFHTTPRequestOperation是一个子类,因此该方法也应该在AFHTTPRequestOperation中可用。

我没有太多的客观体验,所以也许我做的事情很傻,但我找不到编译错误的原因。

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题。我不得不定义

#define _AFNETWORKING_PIN_SSL_CERTIFICATES_

在我试图调用setWillSendRequestForAuthenticationChallengeBlock的文件中:

我知道cocoapods已经在Pods-prefix.pch中执行了#define,并且没想到它应该再次定义。