2013-06-28 339 views
0

我想在IOS中運行下面的代碼。無法識別AFHTTPRequestOperation選擇器錯誤setAuthenticationAgainstProtectionSpaceBlock:

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

至於我可以看到該塊,我傳球有正確的返回類型和參數。我在這裏做錯了什麼?

+0

AFHTTPRequestOperation是AFURLConnectionOperation的子類:「@interface AFHTTPRequestOperation:AFURLConnectionOperation」 – user229487

+0

這似乎是正確的。刪除評論,以避免混淆......奇怪 – Alladinian

+0

也許該操作爲空,並且您沒有正確初始化它? –

回答

5

AFURLRequestOperation根據是否定義了_AFNETWORKING_PIN_SSL_CERTIFICATES_,使用某些可用的代理回調方法進行條件編譯。

如果是(這是從CocoaPods安裝時的默認值),setWillSendRequestForAuthenticationChallengeBlock:將可用。否則setAuthenticationAgainstProtectionSpaceBlock:setAuthenticationChallengeBlock:將可用。

setWillSendRequestForAuthenticationChallengeBlock對應於connection:willSendRequest:forAuthenticationChallenge:,它是the preferred delegate method to handle challenges

相關問題