我试图在localstorage中缓存
JSON数据,以便在没有互联网连接时加载它.它工作正常,但当我重新启动应用程序时,我认为本地存储已清除
这是我的代码:
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')),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>'); }); }) }
怎么了??
解决方法
从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