我似乎对localStorage和Phonegap存在问题。从我的理解移动safari应该保持本地存储,无论该应用程序是否在内存中。出于某种原因,当我从内存中清除我的应用程序并重新启动它时,localstorage缓存已经消失(我可以确认 实际上是在设置数据)。
有什么想法吗?
这就是我为解决这个问题而采取的措施:
function onDeviceReady() {
navigator.network.isReachable("google.com", reachableCallback, {});
}
// Check network status
function reachableCallback(reachability) {
// There is no consistency on the format of reachability
var networkState = reachability.code || reachability;
var states = {};
states[NetworkStatus.NOT_REACHABLE] = 'No network connection';
states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
if (networkState != 0) online = true;
}
////////// Checking navigator.onLine before document ready is key ///////////
var online = navigator.onLine || false;
$(document).ready(function() {
$(document).bind('deviceready', function(){
onDeviceReady()
})
})
答案 0 :(得分:0)
我只是将真实答案复制到答案中,而答案全都来自@nic aitch
弄清楚了。这根本不是localStorage的问题。退出应用后,商店确实存在。问题是由于jQuery文档准备就绪后发生的Phonegap网络回调。
这就是我要解决的问题:
function onDeviceReady() {
navigator.network.isReachable("google.com", reachableCallback, {});
}
// Check network status
function reachableCallback(reachability) {
// There is no consistency on the format of reachability
var networkState = reachability.code || reachability;
var states = {};
states[NetworkStatus.NOT_REACHABLE] = 'No network connection';
states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
if (networkState != 0) online = true;
}
////////// Checking navigator.onLine before document ready is key ///////////
var online = navigator.onLine || false;
$(document).ready(function() {
$(document).bind('deviceready', function(){
onDeviceReady()
})
})