在phonegap IOS上重新启动应用程序后,Localstorage已清除?

时间:2013-04-10 10:27:32

标签: ios cordova

我正在尝试在localstorage中缓存JSON数据,以便在没有Internet连接时加载它。它工作正常,但当我重新启动应用程序时,我认为本地存储已清除

这是我的代码:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

    document.addEventListener("offline", function() {
    alert("No internet connection");


    $.each(JSON.parse(localStorage.getItem('foo')), function(key, val) {
    if(!(val.php)){val.php=0;}
$('ul.get-mertchant').append('<li> <a href="azkadenya.html?id=' + val.nid + '&nop='+ val.php +'" class="li-link"><div class="circle-img"><img src="'+ val.logo + '" /></div><div class="merchant-info"><h1>'+ val.node_title +'</h1><p>You Have '+ val.php +' Binggz</p></div><div class="more-icon"></div></a> </li>');
}); 

}, false);
    $.getJSON('mywebsite/views/services_merchant_mobile', function(data) {
        localStorage.setItem('foo', JSON.stringify(data));

var items = [];
$.each(JSON.parse(localStorage.getItem('foo')), function(key, val) {
    if(!(val.php)){val.php=0;}
$('ul.get-mertchant').append('<li> <a href="azkadenya.html?id=' + val.nid + '&nop='+ val.php +'" class="li-link"><div class="circle-img"><img src="'+ val.logo + '" /></div><div class="merchant-info"><h1>'+ val.node_title +'</h1><p>You Have '+ val.php +' Binggz</p></div><div class="more-icon"></div></a> </li>');
});

})
}

有什么不对?

1 个答案:

答案 0 :(得分:15)

从IOS 5.1开始,Apple决定将本地存储设为临时区域。如果您需要iOS 5.1上的持久存储,请使用PhoneGap的File API。以下是一些了解此问题的链接。

http://community.phonegap.com/nitobi/topics/phonegapbuild_localstorage_on_ios_5_1

http://docs.phonegap.com/en/2.6.0/cordova_storage_storage.md.html#Storage

Apple也会让您使用本地存储。 iOS PhoneGap app rejected because of the use of localStorage