简体   繁体   English

UIWebView loadRequest:iOS 6中的NSURLErrorTimedout连续失败

[英]UIWebView loadRequest: continuously failing with NSURLErrorTimedout in iOS 6

There is an issue where native connection in UIWebView starts failing with timeout. UIWebView中的本机连接启动失败并出现超时问题。 Once timeout starts, only hard exiting app will solve it. 一旦超时开始,只有硬退出的应用程序才能解决它。

Timeout starts randomly but once started, only hard exit will solve it. 超时随机开始,但一旦启动,只有硬退出才能解决它。

Since, hard exit is solving it, it is a client and not server issue. 因为硬退出正在解决它,它是一个客户端而不是服务器问题。 But with the available API of UIWebView I can't figure out the problem. 但是使用UIWebView的可用API,我无法弄清楚问题。

It is till now seen only in iOS6 iPhone and iPad. 到目前为止只能在iOS6 iPhone和iPad上看到它。 I am hitting same URL every time and I am caching JS, CSS resources (maybe something is wrong with iOS6 webview cache). 我每次都在点击相同的URL,我正在缓存JS,CSS资源(可能是iOS6 webview缓存有问题)。

//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];
    }
}

Can you change NSURL code line like this: 您可以像这样更改NSURL代码行:

NSURL * url = [NSURL URLWithString:rephrasing[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

Maybe it will solve your problem 也许它会解决你的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM