2012-05-28 95 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