Storage gets cleared every other day (IOS14)

I have an app created in ionic-v3 that when after login uses preferences stored in storage to load data and if no preferences are set the user gets prompted to set these and they’ll get stored. I have however gotten some complaints from users that they need to set these preferences almost every time but sometimes it can go a couple of days before the storage is cleared again.

I couldnt recreate this issue on devices with version 13.x but when upgrading one of my devices to 14.3 i’m starting to experience the same issues as the users, when checking the logs in xcode while running the app i cannot see anything out of the ordinary and there’s a seemingly randomness to the bug its hard to pinpoint the issue other than this version of IOS are having problems with persisting storage in browser.

Anyone else on Ionic v3 experiencing these kinds of issues with the latest IOS version?

Hi.
If you are running web only app, then you may be suffering from the fact that local storage in iOS is not guaranteed to persist. iOS policy is to clean whenever it feels like it… I think this is something at least reported many times in the past.

Maybe setting the storage driver (if you use Ionic Storage) to async may help a bit…

If you run with cordova storage and sqlite, then I don’t know.

1 Like

I’m running as native IOS / Android apps with Ionic Storage so it should be using sqlite but maybe i should doublecheck that. Thanks for your reply!

you know it…?

driverOrder: ['sqlite', 'indexeddb', 'websql']

When i check in the browser i get this configuration:

_config:
  dbKey: "_ionickey"
  description: ""
  driver: "asyncStorage"
  driverOrder: (4) ["sqlite", "indexeddb", "websql", "localstorage"]
  name: "_ionicstorage"
  size: 4980736
  storeName: "_ionickv"
  version: 1

Which makes sense as im running it in the browser i guess?

And here is the config for running it on an android phone:

_config:
  dbKey: "_ionickey"
  description: ""
  driver: "cordovaSQLiteDriver"
  driverOrder: (4) ["sqlite", "indexeddb", "websql", "localstorage"]
  name: "_ionicstorage"
  size: 4980736
  storeName: "_ionickv"
  version: 1

So it looks like I have the right order on android atleast (its not specified in app.module). However I dont have access to a iphone or mac so i cannot check the config on IOS right now. But maybe i should add driverOrder to the IonicStorageModule.forRoot() anyway as a precaution?

Do you have the cordova-sqlite-storage Plugin installed?

ionic cordova plugin add cordova-sqlite-storage
2 Likes

Yes everything seems to be in order

<plugin name="cordova-sqlite-storage" spec="^2.5.2" />

console.log(this.platform.driver) will tell you what is actually used. The system will fall back on the driver order - giving headaches as well. The config itself may be too little info to debug?

In Android you can use ADB to trace other messages, at native level. iOS has similar thing?

Horror bugs like these may require also remote logging, where you log usage by uploading realtime console.logs. For instance, upload the driver used, store a value and retrieve it, and show the results. Etc. Maybe be a bit overkill, but at least you can start figuring out patterns.

1 Like

That is true, i used the response from the storage class ready() method, tried again with the storage.driver but luckily it was the same “cordovaSQLiteDriver”.

Im not sure what ADB is but i use the chrome://inspect/#devices to read the logs, not sure if there’s something similiar in Xcode maybe?

However your comment gave me one idea, when i check if there is a value stored i dont check if storage is ready so maybe its trying to get a value before the cordovaplugin is initiated which then would maybe fallback to another driver ? Or does it work like that? Or will it wait for the plugin to become ready? The get-method is in form of a promise so maybe it does wait.

Yes, worst case scenario i will have to do live logging, hopefully its a last resort i dont have to visit.

But i appreciate all the help man now i have some new things to try. Will head to the office tomorrow and get a hold of a mac and iphone.

if u use cordova, you HAVE to wait until cordova is ready
Besides waiting until storage is ready
ADB is low level debugging monitor. Basically looking at the android syslogs etc on the device.
It will give you a dumpload of entries, and in between you will be able see potentially erorrs and warnings

1 Like

I would be very surprised if waiting on storage wasn’t sufficient, and a cursory glance at the source would seem to back that up: the _dbPromise inside Ionic Storage bubbles up the return value of localForage’s setDriver call.

2 Likes

This would explain past issues i’ve had with storing the preferences, will wrap it in a platform.ready and storage.ready check, thank you. As for checking what driver is used on IOS i finally was able to check on an Ipad and i get asyncStorage when running via XCode and checking the logs via Safari, if i try and add

driverOrder [“sqlite”, “indexeddb”, “websql”, “localstorage”]

to my storageModule it still chooses asyncStorage so something isnt quite right with my plugins i would assume because if i run cordova plugin list i get:

Windows:
cordova-sqlite-storage 2.5.2 “Cordova sqlite storage plugin”

Mac:
cordova-sqlite-storage 3.4.0 “Cordova sqlite storage plugin” - cordova-sqlite-storage plugin version

Also on mac the list of plugins is followed by an error for running the command:

No such file or directory, open ‘/.config/configstore/cordova-config.json’

So im going dig deeper into my plugins as they seem to fault.

Again, thank you guys for all the help you given me, its more than i’ve asked for.

1 Like

Good luck and happy to have helped.
Seems indeed sqlite is not kicking in.
Maybe try a bare project with only sqlite to see if and how you get it to work? Without all the other stuff around it

1 Like

Not a bad idea, will try and do that! Again thanks and have a good weekend!

Update for future references: I removed cordova-sqlite-storage plugin and reinstalled it aswell as doing an npm install. I rebuilt the project again and the cordovaSQLite driver was recognised as the driver to use, hopefully this will resolve the issue but only time can tell. I didnt know which answer from Tommertom to mark as the solution as each respons got me a little closer to identifying the faulty plugin and fixing it so but hopefully his/her latest respons will suffice.

1 Like