Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

uiwebview - NSMutableURLRequest timeout doesn't trigger if data starts to load but not webViewDidFinishLoad

I am loading a UIWebview and requesting a URL that can take some time to finish loading. The request starts and begins to receive data. However, it doesn't appear that the request finishes. The webViewDidFinishLoad never triggers nor does the webView didFailLoadWithError: callback.

Does a timeout of a NSURLRequest only occur if there is no response receiving data or does it trigger if the request doesn't complete in that interval as well?

If it's the former, is there an elegant solution to timing out the request?

Relevant code is:

Load the request:

- (void) loadRequest { NSString *targetURL = @"http://myrequestUrl/"; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: targetURL] cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 15.0] autorelease];

[request setHTTPBasicID: [[self credentialManager] userID] password:[[self credentialManager] password]];
[webView loadRequest:request];

Delegate to respond to timeout

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible: NO]; [alert hide]; [alert autorelease]; alert = nil; NSLog(@"error - %@", error); [self showRetryPrompt: error];
}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The timeout for the NSURLRequest is for the connection. If you get connected and it just takes a long time for the server to response, he timeout will do you no good. You will need to setup your own NSTimer for the timeout you want and cancel the request yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...