Search code examples
iphonensfilemanager

Accessing .html file in my Supporting Files directory on iPhone


I was trying to display formatted text and did some research here on SO and ppl said to draw it with CG or use html and throw it in a UIWebView. As UIWebView being the easier option, I formatted my document in .html and dropped it into my folder like so:

Supporting Files/Data/Template.html

How do I access this file to show in a UIWebView?

I know I can get my documents by doing:

- (NSURL *)applicationDocumentsDirectory {
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

But after that, I'm stuck. I'm not sure how I would access my Template.html. Thanks


Solution

  • Assuming that you already have the NSURL to the offline template.html file.

    NSURLRequest * offlineRequest = [NSURLRequest requestWithURL:offlineURL];
    UIWebView * webview = [[[UIWebView alloc] init] autorelease];
    [webview loadRequest:offlineRequest];