我想在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
至於我可以看到該塊,我傳球有正確的返回類型和參數。我在這裏做錯了什麼?
AFHTTPRequestOperation是AFURLConnectionOperation的子類:「@interface AFHTTPRequestOperation:AFURLConnectionOperation」 – user229487
這似乎是正確的。刪除評論,以避免混淆......奇怪 – Alladinian
也許該操作爲空,並且您沒有正確初始化它? –