SDWebImage 載入https報錯 無法載入問題

獨樂樂發表於2018-07-13

https://stackoverflow.com/questions/41854908/nsurlsession-nsurlconnection-http-load-failed-kcfstreamerrordomainssl-9802-in

1.SDWebImageDownloaderOperation.m 中

  • (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {

    NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling; __block NSURLCredential *credential = nil;

    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

     if (!(self.options & SDWebImageDownloaderAllowInvalidSSLCertificates)) {
         //            disposition = NSURLSessionAuthChallengePerformDefaultHandling;
         disposition = NSURLSessionAuthChallengeUseCredential;
         credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
     } else {
         credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
         disposition = NSURLSessionAuthChallengeUseCredential;
         //        completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
     }
    複製程式碼

    } else {

     if ([challenge previousFailureCount] == 0) {
         if (self.credential) {
             credential = self.credential;
             disposition = NSURLSessionAuthChallengeUseCredential;
         } else {
             disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
         }
     } else {
         disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
     }
    複製程式碼

    }

    if (completionHandler) { completionHandler(disposition, credential); } }

相關文章