2012-05-28 61 views
0

为什么有些https链接不加载WebView。我可以看到一些https url在safari浏览器中加载完美,但是当我尝试在webview中加载相同的url时,它不会加载。可能是因为https有自签名证书?我们不能加载具有自签名证书的WebView中的url吗?为什么有些Https url在WebView中不加载?

编辑: 现在我能够调用

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace 
{ 
    return YES; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; 
} 

不过我HTTPS URL中的WebView没有加载。

回答

0

试试这个:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace 
{ 
    return YES; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
NSArray *trustedHosts = [NSArray arrayWithObjects:@"mytrustedhost",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]; 
} 
+0

我应该在.h文件添加NSURLConnectionDelegate。到目前为止在.h文件中添加了UIViewController 。 – Cyril

+0

加入.m文件。让我知道是否有任何问题 –

+0

我在.m文件中添加了这两种方法。我保持断点,它没有被调用。 :( – Cyril