Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i add html page in my iphone xcode project?

Tags:

html

xcode

iphone

can anyone tell how to add html in my iphone project?? And their is no html option which i click on add new file in class group...why is that???

like image 370
user601367 Avatar asked Mar 05 '11 05:03

user601367


1 Answers

simply create a blank file and rename it to html or add existing html file to the project. the next step depends on how you wish to use the html file.

Say if you want to load a local file called page.html, first you add the file to project,and in the build phases of your project, and the page.html to Copy Bundle Resources, and run this in your app, it writes the file to the documents dictionary of your app/

NSString *Html = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"page" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL];
[Html writeToFile:[[self docPath]stringByAppendingPathComponent:@"page.html"] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[Html release];

and your webview should call this to load the file:

NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [docPaths objectAtIndex:0];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[docPath stringByAppendingPathComponent:@"page.html"]]]];

and it's done.

like image 108
Xiao Xiao Avatar answered Sep 17 '22 13:09

Xiao Xiao