スタック オーバーフローに関する同様の質問があります。
とにかく信頼できないサーバー証明書を受け入れる私のコードは次のとおりです。
- (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
}
}
ただし、サイトを信頼するかどうかをユーザーが選択できるように、変更ビューを提示したいと考えています。
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];
どうやってやるの?