is localStorage on iPad Safari guaranteed to be pe

2019-01-18 04:20发布

问题:

I've seen differences of opinion across the web on this. It has been said that starting with iOS 5.1, local data storage for HTML5 content on the iPad is no longer guaranteed to be persistent, however on Apple's current Safari developer pages (https://developer.apple.com/technologies/safari/html5.html), offline persistence is suggested to be guaranteed.

Does anyone have any recent experience with this subject and able to comment on how reliable the database features of HTML5 are with Safari on iPad?

回答1:

This will probably be enough information:

The w3c spec of localStorage is:

The second storage mechanism (note: localStorage) is designed for storage that spans multiple windows, and lasts beyond the current session. In particular, Web applications may wish to store megabytes of user data, such as entire user-authored documents or a user's mailbox, on the client side for performance reasons.

And on the Apple page:

Safari supports the latest HTML5 offline data storage features. Your application can store its information on the local machine using either a simple key/value-based data store, or a robust SQL database. The data is stored locally and persists across launches of Safari so your application doesn’t need a network connection to access the data, improving startup time and overall performance.

And searching Google (and Yahoo! because of some anti-google freaks) gives me:

In iOS 5.1 Apple have moved the location of localStorage files into a Caches folder which is subject to occasional clean up, at the behest of the OS, typically if space is short. It is likely that Apple have done this to stop localStorage being backed up to iCloud.

localStorage not accessible in IOS-6 Safari

I am not able to access localStorage in Safari (IPad with IOS-6). For example, the following code is working fine in Windows on all browsers and on (iPad with iOS-5) but not in iOS-6: localStorage.setItem("var","5"); alert(localStorage.getItem("var"));

Answer:

I was able to fix the issue by turning off private browsing on the iPad. I came across the solution from the reference : https://github.com/cloudhead/less.js/issues/312#issuecomment-2994845



回答2:

Yes, Apple cleans up localstorage when the device is low on storage space. (I actually tested this and confirm it with a certainty).