didFailLoadWithError is called with UIWebView even though page later loads(即使页面稍后加载,也使用 UIWebView 调用 didFailLoadWithError)
问题描述
我有一个 UIViewController,它是一个 UIWebViewDelegate,里面有一个 UIWebView.我正在尝试加载特定的 URL
I have a UIViewController which is a UIWebViewDelegate and has a UIWebView inside of it. I am trying to load a particular URL
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
但是didFailLoadWithError
delegate方法几乎是瞬间被调用,错误对象是:
But the didFailLoadWithError
delegate method is almost instantly called, and the error object is:
Did fail load with error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1a66c0 {NSErrorFailingURLKey=www.somewebsite.com, NSErrorFailingURLStringKey=www.somewebsite.com}
但是不久之后,您可以看到网站加载正常.
However a short time after, you can see that the website loads just fine.
为什么调用fail方法?以及无论网站是否实际失败,我如何知道它何时实际失败以及何时调用该方法?
Why is the fail method being called? And how do I know when it has actually failed versus when the method was called regardless of if the website actually failed or not?
推荐答案
当页面通过 javascript 或其他方式立即重定向时,您会收到此错误
You can get this error when the page is instantly redirected via javascript or somehow else
您可以通过此处的答案避免显示错误:如何修复 iPhone 3.0 操作系统中的 NSURLErrorDomain 错误 -999
You can avoid showing the error by answer from here: How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS
喜欢
if ([error code] != NSURLErrorCancelled) { //show error alert, etc. }
但我不知道如何识别它被调用的位置.
but I don't know how to recognize where it was invoked.
这篇关于即使页面稍后加载,也使用 UIWebView 调用 didFailLoadWithError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:即使页面稍后加载,也使用 UIWebView 调用 didFailLoadWithError


基础教程推荐
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01