首先如果你的證書是自簽的,那么你的webview是是不是不能加載https的網(wǎng)址。如果是,且出現(xiàn)了如下的問題。那么就請接著看下去.

解決這個問題的辦法,代碼如下:
BOOL _Authenticated;
NSURLRequest * _FailedRequest; (兩個全局變量)
- (void)createWebView {
_webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
_webview.delegate = self;
[self.view addSubview:_webview];
NSString * string = [NSString stringWithFormat:@"%@%@",baseRequest, self.urlString];
NSURL * url = [NSURL URLWithString:string];
_FailedRequest = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.f];
[_webview loadRequest:_FailedRequest];
}
#pragma UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"webview開始加載!");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"webview加載完成!");
}
-(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]) {
NSString * string = [NSString stringWithFormat:@"%@%@",baseRequest, self.urlString];
NSURL* baseURL = [NSURL URLWithString:string];
if ([challenge.protectionSpace.host isEqualToString:baseURL.host]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)pResponse {
_Authenticated = YES;
[connection cancel];
[_webview loadRequest:_FailedRequest];
}。
到這里,運(yùn)行你的demo試試吧,奇跡會發(fā)生!
以上是參考了alstonwei在github上的一個demo的,demo的鏈接是https://github.com/alstonwei/UIWebView-HTTPS-Test。