我試圖執行SSL證書驗證,並實施委託canAuthenticateAgainstProtectionSpace的iOS canAuthenticateAgainstProtectionSpace方法不叫每
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace: (NSURLProtectionSpace*)protectionSpace
{
OSStatus status = SecTrustEvaluate(protectionSpace.serverTrust, &trustResult);
if(status == errSecSuccess)
{
}
else
{
}
}
然而,我注意到,該委託被稱爲第一次爲一個給定的URL,但不隨後嘗試使用相同的URL。我認爲這與緩存響應有關,所以我創建了NSURLRequest,如下所示:
NSURLRequest *request = [[NSURLRequest alloc]
initWithURL: [NSURL URLWithString:_urlString]
cachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval: 10
];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
這也沒有幫助。任何想法,我可以如何獲得canAuthenticateAgainstProtectionSpace方法每次被調用?
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
以上取消認證的挑戰,所以委託canAuthenticateAgainstProtectionSpace被調用每
瘋了,這麼有用的提示!非常感謝你分享這個! :-) – Lepidopteron 2014-02-11 15:23:19