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???
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With