0

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!

2
  • 1
    This might be helpful: Ray Wenderlich: storing app data. Will you also need to store any linked images, stylesheets and/or scripts with your HTML from Parse? Commented Aug 5, 2015 at 21:09
  • Oh wow! thanks I totally forgot to look on that site. I'll try it out. I ultimately will be trying to store linked html and linked images. Will that work with the NSCoding tutorial pulling from Parse? Thanks! Commented Aug 5, 2015 at 21:12

1 Answer 1

1

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:

Sign up to request clarification or add additional context in comments.

3 Comments

I am not too familiar with using NSUserDefaults so I'm wondering how much I could potentially store from this. I could have up to a 100 files to store in the future so would this practical? Thanks
@Ryan NSUserDefaults values are stored in .plist file, is has no limits except available space on the device.
Thanks! This helped out alot

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.