Compatible Data Storage: Is it this hard?

Hi, looking for experiences from other ionic devs on how they handle data storage in a “cross platform” and “cross device” way.

My storage approach:
My ionic app runs on Android, iOS and Desktops (via electron). My general strategy is that I use localforage as a wrapper with the following order:

  1. Prefer cordovaSQLite as storage for iOS
  2. If not available, fallback to IndexDB (it seems its called asyncstorage on android devices)
  3. If not available, fallback to WebSQL
  4. If not available fallback to LocalStorage

Ideally, I would have preferred to use SQLite for both iOS and Android, but some android devices seem to hang when trying to store large binary data (see here)

Now in the Android land, once in a while, I’ve heard user reports that random devices are not able to save my app’s data, which means every time a person runs my app, they have to re-configure all settings.

On further investigation, I found that on those devices, asyncstorage just does not work. localforage does not complain when setting up the data store, but any setItem or getItem fails with no error value {}. And yes, I am using promises correctly.

So now I have a predicament on Android devices:

  1. If I enable sqlite - it may freeze (see bug report above) on some devices
  2. If I enable asyncstorage (indexDB), storage will fail on some devices
  3. If I enable local storage, the system may remove it when it needs to, but practically this is the only way left

The problem however is I can’t just tell a user ‘press this button to switch the driver’ because I can’t really reliably store that state persistently :slight_smile:

So my strategy now is:

a) For Android, first try asyncstorage
b) If it works, try to set and get a key. If this fails, that means this device won’t support asyncstorage
c) If b failed, switch to LocalStorage as a Hail Mary option

And do the above each time the app runs, because there is no way for me to persistently store which data store I am using.

(No problems with Desktop - asyncstorage always works. No problems with iOS - sqlite always works)

Is it this complicated?