RC1 - iOS localStorage is cleared after some time

i am trying to save some settings in the local Storage with android there is no problem, but with iOS the local Storage is cleared after i close the app - an ideas what i can do?

My Ionic Info
Your system information:

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.7
Ionic App Lib Version: 2.1.4
Ionic App Scripts Version: 0.0.36
 "@ionic/storage": "1.1.6"

Yes, solution would be: don’t use localStorage :slight_smile:

Try this instead:

Money quote:

“This plugin is created because of the non-persistent property of LocalStorage in the WebView of Android and iOS. In iOS stored data from LocalStorage can be removed by the OS, when running out of memory.”


thanks, i will try it :slight_smile:

You could also use the recently created Ionic Storage package. With that you will get the best results on all platforms without any special treatment!

1 Like

I used pouchdb for a project, also works fine. It’s a bit more SQL-like

I have also tried the ionic internal storage, but I get the same problem, if i close the iOS App the storage is emptied

i use this version of ionic storge:
"@ionic/storage": "1.1.6"

You still need to install the SQLite plugin for Ionic Storage to store data permanently, but your data shouldn’t disappear right away even if you do just use local storage (it does happen, but it’s quite infrequent) so there might be a different issue.

I’ve been following these instructions: https://github.com/driftyco/ionic-storage
Here is says the Ionic Storage should have a with out-of-the-box support for SQLite, or do I understand something wrong?
And for android and ionic serve there is no problem

import { Storage } from '@ionic/storage';

 setFavoritePlace(place: PlaceModel): PlaceModel {
        this.favoritePlace = place;
        this.storage.set(this.storageKey, place);
        return this.favoritePlace;

    setFavoritePlaceId(placeId: number, callback?: any): number {
        this.favoritePlaceId = PlaceId;
        this.storage.set(this.storageKeyId, placeId).then( (id:number) => {
            if(typeof callback == 'function') {
        return this.favoritePlaceId;

It does support it out of the box, but you still need to install the plugin in your project using:

ionic plugin add cordova-sqlite-storage

i have installed: ionic plugin add cordova-sqlite-storage

if i run my app on ios, the storage shows my variable with the correct value,
but if i close the app and start it again, the storage is empty.

It works finally, but I have no idea why.
I didn’t changed my code but the storage is not cleared, even if i close the app

Here’s a nice to know resource about browser/webview databases: http://nolanlawson.github.io/database-comparison/

1 Like

some time it does not save into database (only on iOS), i have no idea why it happen