Connecting to HTTPS with self-signed certificates on iOS
Add the following to your NSURLConnectionDelegate
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return self.allowSelfSigned && [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
For iOS 9, to disable ATS, add the following to your apps' info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
Written by davewatts
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Https
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#