1.0.0 • Published 7 years ago

cordova-internal-plugins-preferences v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
7 years ago

Sephora cordova plugins - Application preferences plugin

Presentation

This plugin add application settings, with support for non editable textfields.

Features

  • display the settings of the app in the phone general settings

Installation

Add as a cordova dependency, in config.xml (with Cordova 6.x or higher)

 <plugin name="cordova-internal-plugins-preferences" spec="http://gitlab.estore.caas/cordova-plugins/preferences#1.0.0" />

Using the plugin

function ok (value) {}
function fail (error) {}

var prefs = plugins.appPreferences;

// cordova interface

// store key => value pair
prefs.store (ok, fail, 'key', 'value');

// store key => value pair in dict (see notes)
prefs.store (ok, fail, 'dict', 'key', 'value');

// fetch value by key (value will be delivered through "ok" callback)
prefs.fetch (ok, fail, 'key');

// fetch value by key from dict (see notes)
prefs.fetch (ok, fail, 'dict', 'key');

// remove value by key
prefs.remove (ok, fail, 'key');

// show application preferences
prefs.show (ok, fail);

// instead of cordova interface you can use promise interface
// you'll receive promise when you won't pass function reference
// as first and second parameter

// fetch the value for a key using promise
prefs.fetch ('key').then (ok, fail);

Platforms


  1. Native execution on iOS/macOS using NSUserDefaults — docs for iOS
  2. Native execution on Android using android.content.SharedPreferencesdocs
  3. macOS, Windows Phone and Blackberry support have been removed.

Tests


Tests are not been maintained for this version.

Show Preference pane


If you have generated preferences, you can programmatically show preference pane (Android and iOS at this time). On Android your application show native interface for preferences, on iOS you'll be switched to the Settings.app with application preferences opened for you. Either way, you must listen for Cordova resume event to perform preferences synchronization.

Preferences interface generator


Preferences generator installed along with plugin and run every time when you prepare you cordova app.

After plugin installation you can find file app-settings.json within your app folder.

If you want to disable this functionality, please remove app-settings.json.

iOS note: if you have Settings.bundle from external source or previous version of generator cordova prepare will fail. Current version of preference generator trying not to rewrite existing Settings.bundle if it is not generated by plugin. It is save to remove Settings.bundle if it came from previous version of plugin.

Supported controls for iOS:

  • group
  • combo
  • switch
  • textfield
  • title (non editable textfield)

Supported controls for Android:

  • group
  • combo
  • switch - not tested
  • textfield - not tested

Credits

Original version : https://github.com/apla/me.apla.cordova.app-preferences