无法使用重定向在UIWebView中加载HTTPS页面[iOS 9]

Udi*_*itS 9 ssl objective-c uiwebview nsurlconnection ios

我正在尝试使用iOS 9+ 加载https://网页UIWebView,它会出现以下错误:

NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)CFNetwork SSLHandshake失败(-9802)

我已经尝试过各种NSURLConnection使用connection:willSendRequestForAuthenticationChallenge:方法首先使用处理身份验证质询的方法.

虽然这对于直接请求工作正常,但是 (这里实际问题开始)这不适用于网页重定向到具有不同域的另一个页面的情况.

因此,例如,最初我加载UIWebViewwith调用,https://example.com然后该页面重定向到https://someothersecuredomain.com.这是连接失败而connection:willSendRequestForAuthenticationChallenge:未被调用.

以下是我的实施:

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    // Load webview with request url and parameters
    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
    [request setHTTPBody:postBody];
    [request setHTTPMethod: @"POST"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

    self.webView.delegate = self;
    [self.webView loadRequest: request];

    _BaseRequestURL = url;
}

#pragma mark UIWebView delegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    if (![[request.URL absoluteString] isEqualToString:[_FailedRequest.URL absoluteString]]) {

        _FailedRequest = request;
        (void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
        return NO;
    }

    return YES;
}

#pragma mark - NSURLConnectionDataDelegate methods

-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        NSURL *baseURL = [_FailedRequest URL];
        if ([challenge.protectionSpace.host isEqualToString:baseURL.host]) {
            NSLog(@"trusting connection to host %@", challenge.protectionSpace.host);
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
        } else
            NSLog(@"Not trusting connection to host %@", challenge.protectionSpace.host);
    }
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)pResponse {

    [connection cancel];
    [self.webView loadRequest:_FailedRequest];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {

    NSLog(@"connection error : %@", error);
}
Run Code Online (Sandbox Code Playgroud)

这是记录的连接错误:

错误域= NSURLErrorDomain代码= -1200"发生SSL错误,无法与服务器建立安全连接." UserInfo = {NSUnderlyingError = 0x138643250 {Error Domain = kCFErrorDomainCFNetwork Code = -1200"发生SSL错误,无法建立与服务器的安全连接." UserInfo = {NSErrorFailingURLStringKey = https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction,NSLocalizedRecoverySuggestion =您是否还要连接到服务器?,_ kCFNetworkCFStreamSSLErrorOriginalValue = -9802,_kCFStreamPropertySSLClientCertificateState = 0,NSLocalizedDescription = An发生SSL错误,无法建立与服务器的安全连接.,_ kCFStreamErrorDomainKey = 3,NSErrorFailingURLKey = https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction,_kCFStreamErrorCodeKey = -9802}},NSErrorFailingURLStringKey = https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction,NSErrorFailingURLKey = https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction,NSLocalizedRecoverySuggestion =您要连接吗?无论如何,到服务器?,NSLocalizedDescription =发生了SSL错误,无法与服务器建立安全连接.}

根据iOS 9的App Transport Security,我已经将这两个域添加到我的Exception域列表中Info.plist.

这是这样的:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <false/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
        <key>secure.ccavenue.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
</dict>
Run Code Online (Sandbox Code Playgroud)

我真的被困在这里,任何帮助将不胜感激.

PS.已经尝试过这些问题:问题1,问题2,问题3,问题4问题5