bharath gangupalli
bharath gangupalli

Reputation: 550

How to load a local html from native App in iphone

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

Answers (3)

lomanf
lomanf

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...

If you're loading from your App Bundle

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];

If you're loading form a 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

hotpaw2
hotpaw2

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

KishoreK
KishoreK

Reputation: 962

You can refer to Phonegap source code:

PhoneGapDelegate.m

Especially this line and how it gets file from inside www folder:

    NSURL *appURL = [NSURL fileURLWithPath:[PhoneGapDelegate pathForResource:@"index.html"]];

Upvotes: 1

Related Questions