您必须使用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];