ios 如何解决 UIWebView 中的“Frame Load Interrupted”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19713610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve "Frame Load Interrupted" error in UIWebView?
提问by amarkon
In an app I'm contracted to build, I'm pulling a list of YouTube videos and allowing them to be displayed in the app. However, when a user taps a cell in the YouTube view's navigation controller and the modal view with a UIWebView appears, the UIWebView returns the error "Frame load interrupted."
在我签约构建的应用程序中,我正在提取 YouTube 视频列表并允许它们显示在应用程序中。但是,当用户点击 YouTube 视图的导航控制器中的单元格并出现带有 UIWebView 的模式视图时,UIWebView 会返回错误“帧加载中断”。
I've run it through the debugger dozens of times, and everything seems to go well until I initialize the NSURLRequest. When the modal view is displayed, here is the code that runs in the ViewController's -viewDidLoad
method:
我已经通过调试器运行了它几十次,在我初始化 NSURLRequest 之前,一切似乎都很顺利。当显示模态视图时,以下是在 ViewController 的-viewDidLoad
方法中运行的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
_webView = [[UIWebView alloc] init];
_webView.delegate = self;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:_url];
[_webView loadRequest:request];
}
However, when I pull up the debugger on the line [_webView loadRequest:request];
, I see the following:
但是,当我拉起线上的调试器时[_webView loadRequest:request];
,我看到以下内容:
Does anyone know why the UIWebView is returning the error?
有谁知道为什么 UIWebView 返回错误?
回答by Hai Hw
You should check the URL path
It should be @"http://google.com"
instead of @"google.com"
您应该检查 URL 路径
它应该是 @" http://google.com" 而不是 @"google.com"
回答by user3225101
I have the same issue, in my case it turns out to be the MIMEType
not being set properly.
我有同样的问题,就我而言,结果是MIMEType
没有正确设置。
I tested by manually creating a NSURLConnection
with the request from URL, and then implemented:
我通过NSURLConnection
使用来自 URL 的请求手动创建一个进行测试,然后实现:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
to observe the response callback from the connection. The response's MIMEType
turned out to be "pdf/pdf"
instead of "application/pdf,"
and soon as I fix that issue the webview loaded the url just fine.
观察来自连接的响应回调。MIMEType
结果证明响应"pdf/pdf"
不是,"application/pdf,"
一旦我解决了这个问题,webview 就可以很好地加载 url。
Hope this helps.
希望这可以帮助。
回答by Nikos M.
The url you use probably does not recognize the user agent. That was an issue that occured in older iOS versions too, but seems to have returned in iOS 7. Try adding this to your appdelegate didFinishLaunchingWithOptions:
您使用的 url 可能无法识别用户代理。这也是旧 iOS 版本中出现的问题,但似乎在 iOS 7 中又出现了。尝试将其添加到您的 appdelegate didFinishLaunchingWithOptions:
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
回答by Premal Khetani
Use https://www.google.comOr http://www.google.com
使用https://www.google.com或http://www.google.com
actually https://is the keyword.
实际上https://是关键字。
回答by Kernelzero
I faced same issue on iOS 10.2.1 UIWebView.
我在 iOS 10.2.1 UIWebView 上遇到了同样的问题。
when request pdf file with path URL
当请求带有路径 URL 的 pdf 文件时
the pdf file has MIMEType "application/x-pdf".
pdf 文件的 MIMEType 为“application/x-pdf”。
so I changed to "application/pdf" and can read this
所以我改为“应用程序/pdf”,可以阅读这个
回答by sherb
I had a similar problem to those who reported that adding or correcting the mime type fixed the issue. In my case, I was attempting to open a local file without an file extension (e.g. "my-dir/my-file") and that resulted in the dreaded "Frame Load Interrupted"
error (along with "Unbalanced calls to begin/end appearance transitions for UIViewController"
). Adding the file extension (e.g. "my-dir/my-file.pdf") corrected the problem for me.
我遇到了与那些报告添加或更正 mime 类型修复了问题的人类似的问题。就我而言,我试图打开一个没有文件扩展名的本地文件(例如“my-dir/my-file”),这导致了可怕的"Frame Load Interrupted"
错误(以及"Unbalanced calls to begin/end appearance transitions for UIViewController"
)。添加文件扩展名(例如“my-dir/my-file.pdf”)为我解决了这个问题。
回答by dave
The reason the frame load interruptederror is being displayed is that www.youtube.com
is performing a redirect to m.youtube.com
, which UIWebView doesn't like. To wildly speculate, I would cite possible security implications? I was able to resolve this issue by linking directly to the mobile site, removing the need for youtube to redirect.
显示帧加载中断错误的原因是正在www.youtube.com
执行重定向到m.youtube.com
UIWebView 不喜欢的。为了疯狂推测,我会引用可能的安全隐患?我能够通过直接链接到移动网站来解决此问题,无需 youtube 进行重定向。
回答by rishabh
Its quite clear.. you're not setting the "frame" of WebView. Use this :
它很清楚......你没有设置WebView的“框架”。用这个 :
_webView = [[UIWebView alloc] initWithFrame:self.view.frame]; //give a proper Rect value
_webView.delegate = self;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:_url];
[_webView loadRequest:request];