Skip to main content

Native Storage

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:

npm install @ionic-enterprise/nativestorage
npx cap sync

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:

NameTypeDescription
referencestring-

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:

NameTypeDescription
referencestring-

Returns: Promise<any>


setItem

setItem(reference: string, value: any): Promise<any>

Stores a value

Parameters:

NameTypeDescription
referencestring-
valueany-

Returns: Promise<any>