2

How can I load a HTML from the local file system?

I have seen many questions like this but they are all referring to a file that is within a bundle. I would like to load from a path such as/Users/Abs/Documents/ - I think the ios simulator has access to this as I can save files to my local /Users/Abs/Documents/ directory.

But I don't know how to load a HTML file to the UIWebView.

How can I edit the below to achieve this:

[web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index.html" ofType @"html"]isDirectory:NO]]]; 

2 Answers 2

11

use below code it will work

NSString *filePath=[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; [webView loadData:[NSData dataWithContentsOfFile:filePath] MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:nil]; 
Sign up to request clarification or add additional context in comments.

Comments

2
NSURL *url = [NSURL URLWithString:@"/Users/Abs/Documents/index.html"]; NSURLRequest *req = [NSURLRequest requestWithURL:url]; [web loadRequest:req]; 

Note that this is only useful when working in the simulator, because apps on a device are sandboxed and can only get to files in their bundle.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.