diff --git a/src/index.ts b/src/index.ts index f9cafe1d65..f768c8a108 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import { AndroidFingerprintAuth } from './plugins/android-fingerprint-auth'; import { AppAvailability } from './plugins/appavailability'; import { Appodeal } from './plugins/appodeal'; import { AppRate } from './plugins/apprate'; +import { AppPreferences } from './plugins/apppreferences'; import { AppUpdate } from './plugins/app-update'; import { AppVersion } from './plugins/appversion'; import { Badge } from './plugins/badge'; @@ -138,6 +139,7 @@ export * from './plugins/admob'; export * from './plugins/alipay'; export * from './plugins/android-fingerprint-auth'; export * from './plugins/appavailability'; +export * from './plugins/apppreferences'; export * from './plugins/appodeal'; export * from './plugins/apprate'; export * from './plugins/app-update'; @@ -270,6 +272,7 @@ window['IonicNative'] = { Alipay, AndroidFingerprintAuth, AppAvailability, + AppPreferences, Appodeal, AppRate, AppUpdate, diff --git a/src/plugins/apppreferences.ts b/src/plugins/apppreferences.ts new file mode 100644 index 0000000000..3f5430ea07 --- /dev/null +++ b/src/plugins/apppreferences.ts @@ -0,0 +1,133 @@ +import { Cordova, Plugin } from './plugin'; +import { Observable } from 'rxjs/Observable'; + +/** + * @name AppPreferences + * @description + * This plugin allows you to read and write app preferences + * + * @usage + * ``` + * import { AppPreferences } from 'ionic-native'; + * + * AppPreferences.fetch('key').then((res) => { console.log(res); }); + * + * + */ +@Plugin({ + pluginName: 'AppPreferences', + plugin: 'cordova-plugin-app-preferences', // npm package name, example: cordova-plugin-camera + pluginRef: 'plugins.appPreferences', // the variable reference to call the plugin, example: navigator.geolocation + repo: 'https://github.com/apla/me.apla.cordova.app-preferences', // the github repository URL for the plugin +}) +export class AppPreferences { + + /** + * Get a preference value + * + * @param {string} dict Dictionary for key (OPTIONAL) + * @param {string} key Key + * @return {Promise} Returns a promise + */ + @Cordova({ + sync: true, + callbackOrder: 'reverse' + }) + static fetch(dict: string, key?: string): Promise { return; } + + /** + * Set a preference value + * + * @param {string} dict Dictionary for key (OPTIONAL) + * @param {string} key Key + * @param {string} value Value + * @return {Promise} Returns a promise + */ + @Cordova({ + callbackOrder: 'reverse' + }) + static store(dict: string, key: string, value?: string): Promise { + return; + } + + /** + * Remove value from preferences + * + * @param {string} dict Dictionary for key (OPTIONAL) + * @param {string} key Key + * @return {Promise} Returns a promise + */ + @Cordova({ + callbackOrder: 'reverse' + }) + static remove(dict: string, key?: string): Promise { return; } + + /** + * Clear preferences + * + * @return {Promise} Returns a promise + */ + @Cordova({ + callbackOrder: 'reverse' + }) + static clearAll(): Promise { return; } + + /** + * Show native preferences interface + * + * @return {Promise} Returns a promise + */ + @Cordova({ + callbackOrder: 'reverse' + }) + static show(): Promise { return; } + + /** + * Show native preferences interface + * + * @param {boolean} subscribe true value to subscribe, false - unsubscribe + * @return {Observable} Returns an observable + */ + @Cordova({ + observable: true + }) + static watch(subscribe: boolean): Observable { return; } + + /** + * Return named configuration context + * In iOS you'll get a suite configuration, on Android — named file + * Supports: Android, iOS + * @param {string} suiteName suite name + * @returns {Object} Custom object, bound to that suite + */ + @Cordova({ + platforms: ['Android'] + }) + static suite(suiteName: string): Object { return; } + + @Cordova({ + platforms: ['iOS'] + }) + static iosSuite(suiteName: string): Object { return; } + + /** + * Return cloud synchronized configuration context + * Currently supports Windows and iOS/macOS + * @returns {Object} Custom object, bound to that suite + */ + @Cordova({ + platforms: ['iOS', 'Windows', 'Windows Phone 8'] + }) + static cloudSync(): Object { return; } + + /** + * Return default configuration context + * Currently supports Windows and iOS/macOS + * @returns {Object} Custom Object, bound to that suite + */ + @Cordova({ + platforms: ['iOS', 'Windows', 'Windows Phone 8'] + }) + static defaults(): Object { return; } + +}