There is a similar question on stack overflow.
Here is my code which will accept the untrusted server certificate anyway.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)space
{
//We can always attempt to authenticate...
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodServerTrust) {
[[challenge sender] useCredential:[NSURLCredential credentialForTrust:[[challenge protectionSpace] serverTrust]] forAuthenticationChallenge:challenge];
} else {
// Other situation
}
}
However, I want to present an alter view to let the user chose whether or not trust the site.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
[[challenge protectionSpace]host] message:@"Do you trust this site?"
delegate:self cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", @"Just once", nil];
[alert show];
How can I do that?