iOS 開発の学習を始めたばかりで、ssl を使用する Web サイトから画像を取得しようとしています。ブラウザー (ラップトップ) を介してサイトに接続すると、ルート証明書が信頼されていないという警告が表示されます。ウェブサイトの所有者ではありませんが、完全に信頼できます。私の最初の試み:
self.eventImage.image = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:imageUrl]]];
だから私はこのエラーが発生します
NSURLConnection/CFURLConnection HTTP ロードに失敗しました (kCFStreamErrorDomainSSL、-9807)
iOS Webブラウザーを起動してユーザーを画像リンクに送信しようとしましたが、それを行うと、信頼できるかどうかを尋ねるメッセージが表示されます。「はい」を押すと、画像が表示されますが、画像が必要ですアプリケーション内に表示されます。
Web ビューも使用しようとしましたが、うまくいきませんでした。
ここでの同様の質問のほとんどは、これを使用することを提案しました
- (BOOL)connection:(NSURLConnection *)
connection canAuthenticateAgainstProtectionSpace:
(NSURLProtectionSpace *)protectionSpace {
return NO;
//return [protectionSpace.authenticationMethod isEqualToString:
// NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)
connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge {
NSString *imageUri =[self.detailItem objectForKey: @"image"];
NSArray *trustedHosts = [[NSArray alloc]initWithObjects:imageUri, nil];
if ([challenge.protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust])
if ([trustedHosts containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:
challenge.protectionSpace.serverTrust] forAuthenticationChallenge:
challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
しかし、これらの 2 つのメソッドは、追加しても呼び出されませんでした。