I would like to display HTML files included in an application bundle, but when I go to create a new document, I don't clearly see how to include HTML, except as an empty document.
What's a correct "<p>Hello, world!</p>" for, ideally, including HTML files as resources?
Thanks,
Go to "Applications" > your app (iFile, GoodReade or whatever yours) > Documents. And you are there. Open your HTML files. Now you can go anywhere to and fro without problem.
Xcode offers several ways to add existing files and folders to your project: Drag the files from the Finder into the Project navigator. Click the Add button (+) in the Project navigator's filter bar, and choose Add Files to “projectName”. Choose File > Add Files to “projectName”.
From here: Load resources from relative path using local html in uiwebview
Drag the resource into your xcode project (I dragged a folder named www from my finder window), you will get two options "create groups for any added folders" and "create folders references for any added folders". Select the "create folder references.." option. Use the below given code. It should work like a charm.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
Now all your relative links(like img/.gif, js/.js) in the html should get resolved.
AFAIK there is no HTML file template and neither decent HTML editing capabilities in Xcode. So I suggest to edit the HTML files with another editor and add them to your project - you can either drag & drop or use right click and "add files to ...".
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