Phonegap iOS 5.1 and localStorage

痞子三分冷 提交于 2019-11-26 10:57:34

问题


I was using localstorage for save one value in my App, that works with PhoneGap, but when Apple has released the new iOS 5.1, my App now doesn\'t save the value.

Does anybody know how to solve this problem?

Thank you very much!!!

Edit: I put the code I was using:

window.localStorage.setItem(\"login\", $(\'#login\').val());

I use it for save the value, and I use it for read the value:

function onDeviceReady() {
    var login = window.localStorage.getItem(\"login\");

    if (login != null) {
        $(\'#login\').val(login);
    }
}

But when I close the App, the values are not saved.


回答1:


There was a large thread in the phonegap group that talked about this problem. Basically its because they now treat localStorage as a temp item which can be deleted at any point. Never fear there are very smart people at work!

here's the thread - https://groups.google.com/forum/?fromgroups#!topic/phonegap/RJC2qA9sDnw

here's the code - http://pastebin.com/5881768B




回答2:


In iOS 5, localstorage was made persistent by default, by Apple. In iOS 5.1, localstorage was made a temporary folder that could be deleted by the OS any time storage was constrained. In iOS 6, localstorage was made an optionally persistent folder with a flag in the setting.

Phonegap 2.0 targeted iOS 5.1 and provided a plugin mechanism to provide persistence even though iOS did not.

With iOS 6 and phonegap 2.1 attempt was made to use the plugin only if the iOS version is 5.1 and fall back to the iOS native mechanism for persisting the folder.

However there is a bug with this fix, on iOS 6, where the localstorage folder gets deleted the first time, the data is stored: https://issues.apache.org/jira/browse/CB-1535 The bug report also has the patch; however it is not yet scheduled to be a part of any of the PhoneGap release version; so you would have to manually apply the patch.



来源:https://stackoverflow.com/questions/9664392/phonegap-ios-5-1-and-localstorage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!