Native Storage
Native storage of variables in Android and iOS
Repo: https://github.com/TheCocoaProject/cordova-plugin-nativestorage
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-nativestorage $ npm install --save @ionic-native/native-storage@4
- Add this plugin to your app's module
Supported platforms
- Android
- Browser
- iOS
- macOS
- Windows
Usage
import { NativeStorage } from '@ionic-native/native-storage';
constructor(private nativeStorage: NativeStorage) { }
...
this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
.then(
() => console.log('Stored item!'),
error => console.error('Error storing item', error)
);
this.nativeStorage.getItem('myitem')
.then(
data => console.log(data),
error => console.error(error)
);
Instance Members
setItem(reference, value)
Stores a value
Param | Type | Details |
---|---|---|
reference |
string
|
|
value |
Returns: Promise<any>
getItem(reference)
Gets a stored item
Param | Type | Details |
---|---|---|
reference |
string
|
Returns: Promise<any>
keys()
Retrieving all keys
Returns: Promise<any>
remove(reference)
Removes a single stored item
Param | Type | Details |
---|---|---|
reference |
string
|
Returns: Promise<any>
clear()
Removes all stored values.
Returns: Promise<any>