您好,我在我的混合应用中使用了localStorage,该应用是使用离子框架开发的。一切正常,但最近我们注意到,如果我将我的应用程序放在后台更长时间,比如5-6个小时,当我重新打开应用程序时,它在localStorage中失去了它的价值。但是如果我强制退出我的应用程序并重新打开它,它会正常工作,然后它会获得localStorage中的所有值……对我来说很奇怪,因为这只在IOS中发生,而Android运行得非常好……
代码:
function initState() {
if (userService.token().token) {
$q.all([
panelService.panelGET(),
userService.userGET(),
authenticationService.sessionGET()
]).then(function (data) {
console.log('InitState: ', data);
if (data[0]) {
checkTouchId();
} else {
next(data);
}
});
} else {
if (localStorageService.get('welcome')) {
window.location.hash = 'signin';
} else {
window.location.hash = 'welcome';
localStorageService.set('welcome', true);
}
}
}在OnPlatformReady事件中调用initState() ...
userService.token().token正在从localStorage获取令牌密钥...
发布于 2016-03-28 16:26:17
我认为使用$ionicView.enter缓存.Cache视图的问题是这样的
$scope.$on('$ionicView.enter', function(e) {
//call your initState() function here
});有关$ionicView.enter Refer this QA的更多信息
https://stackoverflow.com/questions/36257191
复制相似问题