Native Storage in Ionic 2 on Android Marshmallow


#1

Hey guys!

Lately, I’ve been using Ionic 2 for an app that I’m working on. I get the data from a REST endpoint and I want to store that data on a device running Marshmallow using Ionic 2’s Native Storage. The following is my code:

   NativeStorage.getItem('records')
                     .then(
                         (records) => {                                                             
                             if(records) {
                                 // do something with the data    
                             } else {
                                 // something else 
                             }
                         },
                         err => this.toast("ERROR", err)
                     );   

As soon as the run the above code on my device, I get an error toast message : {"code":2, "source": "Native", "exception":null}

Can anyone please point out my mistake? Plus Is there is a better alternative to using Native Storage?

All the necessary plugins are in place!


Get data with the Cordova NativeStorage Plugin error
#3

That’s just how the NativeStorage plugin works: it returns an error if the item doesn’t exist. Error code 2 is ITEM_NOT_FOUND.