您必须使用NSURLConnectionDelegate
来允许 HTTPS 连接,并且 iOS8 有新的回调。
已弃用:
connection:canAuthenticateAgainstProtectionSpace:
connection:didCancelAuthenticationChallenge:
connection:didReceiveAuthenticationChallenge:
相反,您需要声明:
connectionShouldUseCredentialStorage:
- 发送以确定 URL 加载程序是否应使用凭证存储来验证连接。
connection:willSendRequestForAuthenticationChallenge:
- 告诉代理连接将发送一个身份验证质询请求。
willSendRequestForAuthenticationChallenge
您可以challenge
像使用已弃用的方法一样使用,例如:
// Trusting and not trusting connection to host: Self-signed certificate
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];