How to resolve “Frame Load Interrupted” error in UIWebView?

浪子不回头ぞ 提交于 2019-12-04 02:59:46

问题


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."

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:

- (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:

Does anyone know why the UIWebView is returning the error?


回答1:


You should check the URL path
It should be @"http://google.com" instead of @"google.com"




回答2:


I have the same issue, in my case it turns out to be the MIMEType not being set properly.

I tested by manually creating a NSURLConnection with the request from URL, and then implemented:

-(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.

Hope this helps.




回答3:


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:

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];



回答4:


Use https://www.google.com Or http://www.google.com

actually https:// is the keyword.




回答5:


I faced same issue on iOS 10.2.1 UIWebView.

when request pdf file with path URL

the pdf file has MIMEType "application/x-pdf".

so I changed to "application/pdf" and can read this




回答6:


The reason the frame load interrupted error 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.




回答7:


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.




回答8:


Its quite clear.. you're not setting the "frame" of WebView. Use this :

_webView = [[UIWebView alloc] initWithFrame:self.view.frame]; //give a proper Rect value
_webView.delegate = self;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:_url];
[_webView loadRequest:request];


来源:https://stackoverflow.com/questions/19713610/how-to-resolve-frame-load-interrupted-error-in-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!