Difference between Native Storage and Ionic Storage?


#1

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.


What is difference between native storage and local stroage ionic 2? Which is better for what type of use?
#2

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.


#3

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.


#4

Does Native Storage store JSON objects also ?


#5

Seems so, see the usage example:

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

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


#9

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 !


#10

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)


#11

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