我正在加载一个 UIWebview 并请求一个可能需要一些时间才能完成加载的 URL。请求开始并开始接收数据。但是,请求似乎没有完成。webViewDidFinishLoad 永远不会触发,webView didFailLoadWithError: 回调也不会触发。
NSURLRequest 的超时是否仅在没有响应接收数据的情况下发生,或者如果请求在该时间间隔内也没有完成,它是否会触发?
如果是前者,是否有一个优雅的解决方案来超时请求?
相关代码为:
加载请求:
- (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];
代表响应超时
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible: NO];
[alert hide];
[alert autorelease];
alert = nil;
NSLog(@"error - %@", error);
[self showRetryPrompt: error];
}