Boris88
Boris88

Reputation: 297

WebView not loading an HTML file properly

I have a UIWebView in which I want to load an HTML file from an URL. This is the code I use to load the file with WebView :

NSURLRequest* blogRequest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:self.url]
                                                  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                              timeoutInterval:5.0];
[self.webView setDelegate:self];
[self.webView loadRequest:blogRequest];

The file I want to load (let's say http://example.com/foo.html) is nothing special, just plain text with basic HTML tag in it. The WebView is working properly for normal website, like google.com, but not my custom HTML file. All I get is an empty document.

webViewDidFinishLoad is never reach.

If I load my HTML file locally from my project, there is no problem. So, why isn't it working when downloading from internet? I have absolutely no clue.

Upvotes: 0

Views: 324

Answers (1)

paulvs
paulvs

Reputation: 12053

Do you have a super slow network and your 5 second timeout is expiring? Or, are you implementing a delegate method that is blocking the request?

Try this, it works for me:

NSString *URLString = @"http://example.com/foo.html";
NSURL *URL = [NSURL URLWithString:URLString];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[self.webView loadRequest:request];

Upvotes: 1

Related Questions