How to include HTML files in Xcode / iOS?

I would like to display the HTML files included with the application, but when I move on to creating a new document, I don’t understand how to include HTML except for an empty document.

What is the correct "<p> Hello, world! </p>" ideally, including HTML files as resources?

Thanks,

+6
source share
2 answers

From here: Loading resources from a relative path using local html in uiwebview

Drag the resource into the xcode project (I dragged a folder named www from the Finder window), you will get two options: "create groups for any added folders" and "create folder links for any added folders". Select the option "Create link folder ..". Use the code below. 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 (e.g. img / .gif, js / .js) in html should be allowed.

+10
source

AFAIK there is no HTML file template and there are no good HTML editing features in Xcode. Therefore, I suggest editing HTML files with another editor and adding them to your project - you can either drag or right-click and "add files to ...".

+2
source

Source: https://habr.com/ru/post/953498/


All Articles