cordova – Ionic localstorage不会持续存在

cordova – Ionic localstorage不会持续存在,第1张

概述我正在使用本地存储来存储Ionic中的数据 我的问题是本地存储不会像在Web上那样持久存在. 在iOS上,每隔几天就会删除本地存储,而在Android上则更糟糕,在某些设备上,本地存储就像会话存储一样,在应用关闭时会被擦除. 这是我的本地存储服务: angular.module('app.core').factory('localstorage', ['$window', function ($ 我正在使用本地存储来存储Ionic中的数据
我的问题是本地存储不会像在Web上那样持久存在.

在iOS上,每隔几天就会删除本地存储,而在Android上则更糟糕,在某些设备上,本地存储就像会话存储一样,在应用关闭时会被擦除.

这是我的本地存储服务:

angular.module('app.core').factory('localstorage',['$window',function ($window) {  return {    setobject: function (key,value) {      $window.localstorage[key] = JsON.stringify(value);    },getobject: function (key) {      return JsON.parse($window.localstorage[key] || null);    }  }}]);

我看过这篇文章:http://www.joshmorony.com/a-summary-of-local-storage-options-for-phonegap-applications/

Local storage gets a bit of a bad wrap,and is generally consIDered to
be unreliable. I think the browsers local storage can be a viable
option and it is reasonably stable and reliable,but,it is possible
for the data to be wiped,which means for a lot of applications it’s
not going to be a great option.

这有什么解释吗?

解决方法 在探索了离子的本地存储问题后,我可以说一件事:

如果您需要保留数据,请不要使用它!

我决定使用PouchDB来保持我的数据持久性.

从Ashteya Biharisingh post开始:

The data that is saved in localstorage is supposed to be persisted
even if you close the app or turn off your phone. In most cases this
will work,but there are issues with the way iOS and AndroID manage
localstorage on the devices.

iOS
On iOS 8 the localstorage is sometimes cleared when memory is low,as you can read here.

I recently experIEnced it myself on an Ionic app I was working on. I
got a notification on my iPhone that it was running low on memory and
when I opened up the app the localstorage was empty. I had another app
on my device that was using localstorage as well,but that one was not
cleared.

AndroID
I haven’t tested this extensively on AndroID,but if you read this thread,you’ll see that there are several reports that localstorage doesn’t work as expected.

你可以按照相当不错的指南here

总结

以上是内存溢出为你收集整理的cordova – Ionic localstorage不会持续存在全部内容,希望文章能够帮你解决cordova – Ionic localstorage不会持续存在所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1000833.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存