有一个问题,UIWebView
中的本机连接开始随超时而失败。一旦超时开始,只有硬出口应用程序才能解决它。
超时开始随机启动,但一旦启动,只有硬出口才能解决。
由于硬出口正在解决它,因此是客户端,而不是服务器问题。但是有了UIWebView
的可用API,我无法弄清楚这个问题。
直到现在仅在ios6 iPhone和iPad中看到。我每次都在同一个URL,并且我正在缓存JS,CSS资源(ios6 WebView Cache可能出了点问题)。
//code
//usual webview loading code
//except I am setting cookies everytime before load request
- (void)viewDidLoad
{
[super viewDidLoad];
self.webview.delegate = self;
NSString * urlString;
urlString = @"https://www.myserver.com/";
NSURL * url = [NSURL URLWithString:urlString];
// I create and set some cookies here.
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:self.mobilePageURL mainDocumentURL:self.mobilePageURL];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
if([error.domain isEqualToString:NSURLErrorDomain] && error.code != NSURLErrorCancelled)
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
UIAlertView * alert = [[UIAlertView alloc] init];
NSString * errorMessage = [NSString stringWithFormat:@"%d",error.code];
[alert setMessage: errorMessage];
[alert addButtonWithTitle:@"Ok"];
[alert show];
}
}
您可以像这样更改nsurl代码行:
NSURL * url = [NSURL URLWithString:rephrasing[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
也许它将解决您的问题