iOS 7 webview和localStorage持久性 [英] iOS 7 webview and localStorage persistence

查看:99
本文介绍了iOS 7 webview和localStorage持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PhoneGap / Cordova开发混合应用程序(仅适用于iOS和Android),并希望使用HTML5 localStorage存储内容以供离线访问。



<一个href =http://caniuse.com/#search=localStorage =nofollow noreferrer> http://caniuse.com/#search=local存储说 - 在iOS 5& 6 localStorage数据存储在可能偶尔被操作系统清除的位置。


  1. iOS 7的情况如何(及更高版本)webview,在什么情况下localStorage会持续存在,或者被操作系统或用户清除?


  2. 是否会更新应用程序清除localStorage?


  3. 用户在Safari上清除浏览器历史记录怎么样?这也适用于网页浏览吗?


  4. 我需要担心(或者我可以控制)localStorage在fils系统上的创建位置。我知道它不应该在iCloud上备份。







I有一台设备(iPad)并检查文件系统,我发现localStorage文件位于应用程序沙箱中的〜/ Library / Caches中,请参阅下面的图片。

从文档:



https://developer.apple.com/icloud/documentation/data-storage/index.html
可以再次下载或重新下载的数据应该存储在/ Library / Caches目录中。您应该放在Caches目录中的文件示例包括数据库缓存文件和可下载内容,例如杂志,报纸和地图应用程序使用的文件。



我简单地这样做来设置数据:

  localStorage.setItem('foo','这是FOO值'); 
localStorage.setItem('bar','这是BAR值');


I'm developing a hybrid app (for iOS and Android only) using PhoneGap/Cordova and want to use HTML5 localStorage to store content for offline access.

http://caniuse.com/#search=localStorage says - "In iOS 5 & 6 localStorage data is stored in a location that may occasionally be cleared out by the OS."

  1. What is the situation with an iOS 7 (and later) webview, in what cases will localStorage persist, or get cleared out (by the OS, or the user)?

  2. Will an update to the app clear localStorage?

  3. What about the user clearing browser history on Safari - will that apply to the webview too?

  4. Do I need to worry (or can I even control) where on the fils system the localStorage is created. I understand it should not be backed up on iCloud.


I got a device (iPad) and checking the file system I see that localStorage file is in ~/Library/Caches within the app sandbox, see image below.

From the docs:

https://developer.apple.com/icloud/documentation/data-storage/index.html Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications.

I am simply doing this to set data:

  localStorage.setItem('foo','this is the FOO value');
  localStorage.setItem('bar','and this is the BAR value');

解决方案

If you are using cordova, that problem was fixed long time ago, even for iOS 5 and iOS 6. You shouldn't worry if you are using the latest version of cordova.

这篇关于iOS 7 webview和localStorage持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆