Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include HTML files in XCode / iOS? [closed]

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,

like image 684
Christos Hayward Avatar asked Sep 09 '13 15:09

Christos Hayward


People also ask

How open local HTML file in IOS?

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.

How do I add files to Xcode project?

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


2 Answers

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.

like image 107
Woodstock Avatar answered Sep 17 '22 13:09

Woodstock


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

like image 43
e1985 Avatar answered Sep 19 '22 13:09

e1985