Native Storage
EOL Notice
Native Storage will reach its end-of-life on July 1, 2024, and will no longer receive updates or support. Please see Support Policy for additional information.
The Native Storage plugin provides native storage of variables in Android (SharedPreferences) and iOS (UserDefaults).
Installation
If you have not already setup Ionic Enterprise in your app, follow the one-time setup steps.
Next, install the plugin:
- Capacitor
- Cordova
npm install @ionic-enterprise/nativestorage
npx cap sync
ionic cordova plugin add @ionic-enterprise/nativestorage
Index
Classes
Classes
NativeStorage
usage:
import { NativeStorage } from '@ionic-enterprise/nativestorage/ngx';
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)
);
clear
▸ clear(): Promise
<any
>
Removes all stored values.
Returns: Promise
<any
>
getItem
▸ getItem(reference: string
): Promise
<any
>
Gets a stored item
Parameters:
Name | Type | Description |
---|---|---|
reference | string | - |
Returns: Promise
<any
>
keys
▸ keys(): Promise
<any
>
Retrieving all keys
Returns: Promise
<any
>
remove
▸ remove(reference: string
): Promise
<any
>
Removes a single stored item
Parameters:
Name | Type | Description |
---|---|---|
reference | string | - |
Returns: Promise
<any
>
setItem
▸ setItem(reference: string
, value: any
): Promise
<any
>
Stores a value
Parameters:
Name | Type | Description |
---|---|---|
reference | string | - |
value | any | - |
Returns: Promise
<any
>