gpt4 book ai didi

cordova - ionic 本地存储不持久

转载 作者:行者123 更新时间:2023-12-01 02:00:47 26 4
gpt4 key购买 nike

我正在使用本地存储在 Ionic 中存储数据
我的问题是本地存储不像在 Web 上那样持久。

在 iOS 上,本地存储每隔几天就会被删除一次,而在 Android 上情况更糟,在某些设备上,本地存储就像一个 session 存储,并在应用程序关闭时被删除。

这是我的本地存储服务:

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.



对此有什么解释吗?

最佳答案

在探索了 ionic 中的 localstorage 问题用法后,我可以说一件事:

请勿使用 如果您需要持久保存数据!

我决定使用 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 本地存储不持久,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36700618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com