17

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?

amarkon
  • 341
  • 1
  • 6
  • 17
  • You may want to inspect the UIWebView delegate's didFailWithError and check the domain and error number see if that yields more information – cynistersix Dec 19 '13 at 23:27
  • 1
    Is this an empty page ? – NeverHopeless Mar 14 '14 at 12:00
  • The last answer on here about the redirect to m.youtube seems promising. I also found this: http://stackoverflow.com/questions/19959307/the-joys-of-didfailloadwitherror-uiwebview. And if the file was local and request needs to be formed using UIWebView loadData: – cynistersix Jul 01 '15 at 22:06
  • @amarkon I have a POST request to the server which responds with the PDF data. The fileName with .pdf extension is sent as parameter in application/x-www-form-urlencoded format. I'm getting Error Domain=WebKitErrorDomain Code=102 “Frame load interrupted” error as well. How to solve it? Please help. TIA – Vaibhav Jhaveri Apr 02 '20 at 07:39

10 Answers10

7

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

Hai Hw
  • 1,397
  • 1
  • 16
  • 24
5

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.

TLama
  • 75,147
  • 17
  • 214
  • 392
user3225101
  • 51
  • 1
  • 1
1

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];
Nikos M.
  • 13,685
  • 4
  • 47
  • 61
1

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

actually https:// is the keyword.

Premal Khetani
  • 3,175
  • 1
  • 26
  • 58
1

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.

dave
  • 1,150
  • 1
  • 13
  • 22
1

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

Kernelzero
  • 113
  • 13
1

Swift 5/ WKWebview

The same issue occurs with WKWEBVIEW and similar solution should be provided as UIWebview: In my case it was PDF -

webView.load(Data.init(contentsOf: url), mimeType:"application/pdf", characterEncodingName: "UTF-8", baseURL: url)

This should be used for loading a PDF file from the web.

0

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.

sherb
  • 5,845
  • 5
  • 35
  • 45
0

Don't load webView in case of webView is already is in loading process

if !self.webView.isLoading {
    let request = URLRequest.init(url: url)
    self.webView.load(request)
}

This way, I resolve this issue.

-19

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];
rishabh
  • 1,155
  • 1
  • 10
  • 17
  • 2
    That's not what that means. It's talking about a web frame (a WebKit concept), not a UIView frame. – AriX Sep 19 '14 at 05:51