How to resolve “Frame Load Interrupted” error in U

2019-06-15 00:06发布

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:

enter image description here

Does anyone know why the UIWebView is returning the error?

8条回答
祖国的老花朵
2楼-- · 2019-06-15 00:09

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

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-06-15 00:13

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

actually https:// is the keyword.

查看更多
唯我独甜
4楼-- · 2019-06-15 00:21

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];
查看更多
男人必须洒脱
5楼-- · 2019-06-15 00:24

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.

查看更多
Rolldiameter
6楼-- · 2019-06-15 00:29

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];
查看更多
Melony?
7楼-- · 2019-06-15 00:30

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.

查看更多
登录 后发表回答