Difference between Native Storage and Ionic Storage?

Please tell the main difference between these two storages.

Native Storage


I know that this storage only runs on real device

Ionic Storage


this storage can be used for “ionic serve” also

Please tell when to use which storage.

1 Like

The second thing you linked to is actually “Ionic Storage”, not “SQlite Storage” how you labeled it. I fixed this in your post. This is a very important difference.

1 Like

Both these options are key value stores.

“Native Storage” is a Cordova plugin that works only on devices.
“Ionic Storage” is a javascript library that can optionally be backed by a Cordova plugin for SQlite. Otherwise it is backed by available methods in the Webview.

If you need it to work in the browser, ionic serve as well, use Ionic Storage.
If you want to use the more used of the both, use Ionic Storage.
If you want to use the officially supported and maintained (by the Ionic team) of both, use Ionic Storage (Ionic Native plugins are “only” community maintained)
If you need the last bit of speed, compare the both to find out which is actually faster.

1 Like

Does Native Storage store JSON objects also ?

Seems so, see the usage example:

this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})...

https://ionicframework.com/docs/native/native-storage/#usage

The thing about Ionic Storage is that it gets extremely frustrating when you store objects, because you can’t directly change the value of a property, you have to get the entire object, change the property, and then override the entire object in storage. And it gets even more insane when you have objects in objects and arrays of objects. Yikes !

1 Like

That is exactly the same with Native Storage - actually all key value stores :wink: (Normally this is solved by writing a wrapper that takes care of this so you don’t duplicate this logic everywhere)

I have a problem about persistence on iOS 11 using ionic/storage. After almost one hour the storage.get retrieve empty data. There’s no problem on Android.

 @ionic/storage@2.0.1

    @ionic/cli-utils  : 1.18.0
    ionic (Ionic CLI) : 3.18.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.1.0
    Cordova Platforms  : android 6.3.0 ios 4.5.4
    Ionic Framework    : ionic-angular 3.8.0

System:

    ios-deploy : 1.9.2
    ios-sim    : 6.1.2
    Node       : v6.11.2
    npm        : 2.15.12
    OS         : macOS High Sierra
    Xcode      : Xcode 9.2 Build version 9C40b
1 Like

quick question please,
i’m building an offline app 100%.
i tried ionic storage when i tested in my device when i close and remove app from the background it clear all the data … ??? should i use nativeStorage for this ?
Thanks in advance