Reputation: 1283
I'm using Parse for my iOS app and I'm trying to locally save my HTML file from Parse core data to my device's local storage. I'm doing this so the user can still access the data even when they're offline. I've read about local datastore and cache policy and have tried both. With local datastore, it doesn't let me load the HTML to my UIWebView but it loads everything else (probably due to the HTML needing internet to access it). Cache policy actually works but only accesses the more recent items (just as a cache should work).
I am asking on here to see what I can do to locally save these HTML files from Parse so a user can access them even when the internet is gone.
Thanks!
Upvotes: 0
Views: 326
Reputation: 4595
You can use PFFile
's method getData
to get NSData
and save it to NSUserDefaults
:
let data = file.getData()
NSUserDefaults.standardUserDefaults().setObject(data, forKey: file.name)
...and when you need to read it:
let data = NSUserDefaults.standardUserDefaults().dataForKey(file.name)
This can help you display the page in WebView: How do I convert HTML NSData to an NSString?
Update: UIWebView
has method to show NSData
: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/#//apple_ref/occ/instm/UIWebView/loadData:MIMEType:textEncodingName:baseURL:
Upvotes: 1