当前位置 : 主页 > 手机开发 > cordova >

cordova – Ionic localstorage不会持续存在

来源:互联网 收集:自由互联 发布时间:2021-06-10
我正在使用本地存储来存储Ionic中的数据 我的问题是本地存储不会像在Web上那样持久存在. 在iOS上,每隔几天就会删除本地存储,而在Android上则更糟糕,在某些设备上,本地存储就像会话存储
我正在使用本地存储来存储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

网友评论