大佬教程收集整理的这篇文章主要介绍了xcode – iOS App – 设置UIWebView加载超时,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我加载我的视图中的webView的URLDidLoad像这样(简化):
[webView loadrequest:[NSURLrequest requestWithURL:[NSURL URLWithString:@"http://www.example.com"] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0]];
上面的代码中的timeoutInterval实际上并不“做”任何事情,因为苹果已经在操作系统中设置了240秒,实际上没有超时。
我有我的webView didFailLoadWithError操作设置,但如果用户有一个网络连接,这从来没有被调用。 webView只是继续尝试加载我的networkActivityIndicator旋转。
有没有办法为webView设置超时?
// define NSTimer *timer; somewhere in your class - (void)cancelWeb { NSLog(@"didn't finish loading within 20 sec"); // do anything error } - (void)webViewDidFinishLoad:(UIWebView *)webView { [timer invalidate]; } - (void)webViewDidStartLoad:(UIWebView *)webView { // webView connected timer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self SELEctor:@SELEctor(cancelWeb) userInfo:nil repeats:NO]; }
以上是大佬教程为你收集整理的xcode – iOS App – 设置UIWebView加载超时全部内容,希望文章能够帮你解决xcode – iOS App – 设置UIWebView加载超时所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。