I’m trying to make an iOS app that allows the user to create an unlimited amount of HTML document and save them into the documents folder of the app. This is sort of like a combo question but how can I display a file that is in the documents dictionary.
So my two question are:
How to display HTML file that are in the document dictionary
And
How to allow the user to created unlimited folders and html files
Sorry for the double question…
Saving HTML and Other Text Files to the Documents Directory
First, you need to know the path to your documents directory:
You can create documents and directories there up to the limits of the device storage. Be aware, however, that only files in the root will show up in iTunes Document Sharing.
So, if you have a string
htmlContentand a stringhtmlFilename, you can save it. Do pay attention to the encoding you’re using; the encoding in the HTML header and meta tags (if present) should match the encoding used here.Displaying HTML Files Within Your App
You can display HTML in a
UIWebView. Assuming you have one calledwebView, you can display anyNSURLobject in it:This can include the file you just wrote:
Or, you can put a string into it directly:
If you use a
UIWebViewfor a lot of your functionality, take the time to read the UIWebViewDelegate Protocol Reference.Opening HTML in Safari
It is also possible to tell your application to open URLs elsewhere. This will usually result in Safari opening. However, because Safari does not have access to your app’s document directory, it cannot display documents while they are saved locally.