Reputation: 550
I have an html file 'sample.html' in a folder 'www' under project. How to load this file from the native App..
I searched many sites ,the given samples are for the files from 'Resource'. Please help me in this...
Thanks, Bharath
Upvotes: 1
Views: 2178
Reputation: 2039
The www
folder is not important if you're loading from the App bundle because the build process flat all your bundle files in the same directory.
In your UIViewController try to use something like this...
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"page.html" ofType:@""]];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
www
folder in your Document directory (in example)NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *yourFilePath = [NSString stringWithFormat:@"%@/www/page.html", documentDirectory];
NSURL *url = [NSURL fileURLWithPath:yourFilePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
Hope this helps. Ciao!
Upvotes: 2
Reputation: 70663
If your build is copying this file into the app bundle, then it gets copied into the mainBundle, no www directory.
Upvotes: 0
Reputation: 962
You can refer to Phonegap source code:
Especially this line and how it gets file from inside www folder:
NSURL *appURL = [NSURL fileURLWithPath:[PhoneGapDelegate pathForResource:@"index.html"]];
Upvotes: 1