Reputation: 57916
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]]];
Upvotes: 2
Views: 4808
Reputation: 6323
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];
Upvotes: 11
Reputation: 280
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.
Upvotes: 2