2014-02-12 10 views
11

Ich versuche, eine HTTPS-Webseite, die ein selbstsigniertes Zertifikat hat, in ein UIWebView zu laden. Mit Tipps wie this one, oder this one, funktioniert es unter iOS 6. Das gleiche funktioniert nicht in iOS 7.Bypass kCFStreamErrorDomainSSL Fehler für selbstsignierte Zertifikate auf iOS 7

Wie zu den verknüpften Stack Overflow Fragen, ich benutze auch eine NSURLConnection, um zuerst zu versuchen und vorbei zu kommen das selbstsignierte Zertifikat - das alles vorher versucht sogar, die URL in das UIWebView zu laden.

Wenn die gleichen Versuch in iOS 7, ich folgende Fehlermeldung erhalten:

2014-02-12 16:00:08.367 WebView[24176:5307] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

2014-02-12 16:00:08.370 WebView[24176:70b] An SSL error has occurred and a secure connection to the server cannot be made.

Gibt es eine Behelfslösung dieses in iOS 7 zur Arbeit zu kommen? Im Moment verwende ich die first example.

+0

Versuch zu verwenden, um dies die UIWebViewDelegate Methoden der Umsetzung: http://stackoverflow.com/a/15074358/1694129 –

+0

im Grunde ein Duplikat von http://stackoverflow.com/questions/11573164, das jetzt auch eine Lösung in swift – spirographer

Antwort

17

Bitte folgen Sie dem Link:

in UiWebView - NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -108)

BOOL _Authenticated; 
NSURLRequest *_FailedRequest; 
#pragma UIWebViewDelegate 

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { 
    BOOL result = _Authenticated; 
    if (!_Authenticated) { 
     _FailedRequest = request; 
     NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
     [urlConnection start]; 
    } 
    return result; 
} 

#pragma NSURLConnectionDelegate 

-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { 
     NSURL* baseURL = [NSURL URLWithString:@"your 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 { 
    _Authenticated = YES; 
    [connection cancel]; 
    [webvw loadRequest:_FailedRequest]; 
} 
+0

geschrieben hat Große Antwort. Vielen Dank! – OlivaresF

0

diese Methode in Ihrer Klasse hinzufügen:

-(void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) 
    { 
     NSURL* baseURL = [NSURL URLWithString:@"yourURL"]; 

     if ([challenge.protectionSpace.host isEqualToString:baseURL.host]) 
     { 
      SecTrustRef trust = challenge.protectionSpace.serverTrust; 

      NSURLCredential *cred = [NSURLCredential credentialForTrust:trust]; 
      [challenge.sender useCredential:cred forAuthenticationChallenge:challenge]; 
     } 
     else 
      NSLog(@"Not trusting connection to host %@", challenge.protectionSpace.host); 
    } 
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; 
} 
Verwandte Themen