Ionic App Preferences


Ionic App Preferences plugin– Ionic App Preferences plugin allows us to read and write app preferences. Here in this tutorial we are going to explain to import this plugin and use it.


Ionic App Preferences Plugin Example

You can install App Preferences Plugin simply as below-

Ionic App Preferences Plugin Install:

$ ionic plugin add --save cordova-plugin-app-preferences
$ npm install --save @ionic-native/app-preferences

Supported Platforms

Following Platforms are supported in app preferences –

  • Android
  • BlackBerry 10
  • Browser
  • iOS
  • OS X
  • Windows 8
  • Windows Phone

Example

First Import AppPreferences from ionic native before using it, Here is simple example-

Ionic App Preferences Plugin Example:

import { AppPreferences } from '@ionic-native/app-preferences';

constructor(private appPreferences: AppPreferences) {

  this.appPreferences.fetch('key').then((res) => { console.log(res); });

}

Instance Members

Following Instance Members are available-

  • fetch
  • store
  • remove
  • clearAll
  • show
  • watch
  • suite
  • iosSuite
  • cloudSync
  • defaults

Now let us go one by one to understand the details-

fetch(dict, key)

This method returns the preference value-

Param Type Details
dict string Dictionary For Key(optional)
Key String Key

Returns- Returns Promise any.

store(dict, key, value)

This method sets the preference value-

Param Type Details
dict string Dictionary For Key(optional)
Key String Key
Value String Value

Returns- Returns Promise any.

remove(dict, key)

This method removes the value from the preference-

Param Type Details
dict string Dictionary For Key(optional)
Key String Key

Returns- Returns Promise any.

clearAll()

This method clears the preferences-

Returns- Returns Promise any.

show()

This method shows the native preference interface-

Returns- Returns Promise any.

watch(subscribe)

This method shows the native preference interface-

subscribe(boolean)-True value to subscribe, false – unsubscribe

Returns- Returns Observable.

suite(suiteName)

Supported Platform– Android

This method shows the native preference interface-

suitName(boolean)-Return named configuration context In iOS you’ll get a suite configuration, on Android — named file Supports: Android, iOS.

Returns- Returns Custom Object.

isSuite()

Supported Platform– IOS

cloudSync()

Supported Platform– IOS, Windows, Windows Phone 8

Returns cloud synchronized configuration.

defaults()

Supported Platform– IOS, Windows, Windows Phone 8

Returns default configuration.


Advertisements

Add Comment

📖 Read More