Search code examples
iosobjective-cuiwebviewnsbundle

UIWebView not loading local webpage


I have a super simple webpage that I just want to load a single local file. The file is /Resources/About.html

Here is my code:

NSString *urlPath = [[NSBundle mainBundle] URLForResource:@"About" withExtension:@"html"];
NSURL *url = [NSURL fileURLWithPath:urlPath];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];

What's wrong?


Solution

  • The method URLForResource:withExtension returns an NSURL, not an NSString. You can use the result of that directly in your request.

    NSURL *URL = [[NSBundle mainBundle] URLForResource:@"About" withExtension:@"html"];
    [webView loadRequest:[NSURLRequest requestWithURL:URL]];