看到很多網(wǎng)上說(shuō)設(shè)置清除緩存
self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:htmlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0];
貌似這個(gè)我也沒(méi)用,我出現(xiàn)的bug是版本跟新后網(wǎng)址在iphone手機(jī)上打不開(kāi),新建過(guò)一個(gè)工程后是可以打開(kāi)的,一開(kāi)始認(rèn)為是UIWebView的bug,最后一氣之下卸載重新App Store上安裝居然可以打開(kāi)網(wǎng)址了。。。。。
最后后臺(tái)大佬告訴我說(shuō)iOS是需要做一個(gè)登錄的驗(yàn)證什么的,具體搞后端的肯定明白
開(kāi)始以為是未加入證書驗(yàn)證,然并不是。
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge; {
NSLog(@"WebController Got auth challange via NSURLConnection");
if ([challenge previousFailureCount] == 0) {
_authenticated = YES;
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
// We use this method is to accept an untrusted site which unfortunately we need to do, as our PVM servers are self signed.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
#pragma mark - NSURLConnectionDataDelegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"WebController received response via NSURLConnection");
// remake a webview call now that authentication has passed ok.
_authenticated = YES;
[self.webView loadRequest:_request];
// Cancel the URL connection otherwise we double up (webview + url connection, same url = no good!)
[_urlConnection cancel];
}
我真是什么bug都能碰見(jiàn)啊