feat(cloud-settings): add support for cordova-plugin-cloud-settings (#2494)

* feat(cloud-settings): add support for cordova-plugin-cloud-settings

* refactor
This commit is contained in:
Dave Alden 2018-05-19 11:16:14 +01:00 committed by Daniel Sogl
parent ae6e28de88
commit 400dbcb1fb

View File

@ -0,0 +1,91 @@
import { Injectable } from '@angular/core';
import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core';
/**
* @name Cloud Settings
* @description
* Stores app settings in cloud storage so if the user re-installs the app or installs it on a different device, the settings will be restored and available in the new installation.
*
* @usage
* ```typescript
* import { CloudSettings } from '@ionic-native/cloud-settings';
*
*
* constructor(private cloudSettings: CloudSettings) { }
*
* ...
*
* this.cloudSettings.exists()
* .then((exists: boolean) => console.log("Saved settings exist: " + exists) )
*
* this.cloudSettings.load()
* .then((settings: any) => this.settings = settings)
* .catch((error: any) => console.error(error));
*
* this.cloudSettings.save(this.settings)
* .then((savedSettings: any) => console.log("Saved settings: " + JSON.stringify(savedSettings)))
* .catch((error: any) => console.error(error));
*
* ```
*/
@Plugin({
pluginName: 'CloudSettings',
plugin: 'cordova-plugin-cloud-settings',
pluginRef: 'cordova.plugin.cloudsettings',
repo: 'https://github.com/dpa99c/cordova-plugin-cloud-settings',
install:
'ionic cordova plugin add cordova-plugin-cloud-settings --variable ANDROID_BACKUP_SERVICE_KEY=myapikey',
installVariables: ['ANDROID_BACKUP_SERVICE_KEY'],
platforms: ['Android', 'iOS']
})
@Injectable()
export class CloudSettings extends IonicNativePlugin {
/**
* Indicates if any stored cloud settings currently exist for the current user.
* @return {Promise<boolean>} Will be passed a boolean flag which indicates whether an store settings exist for the user.
*/
@Cordova()
exists(): Promise<boolean> {
return;
}
/**
* Saves the settings to cloud backup.
* @param {object} settings - a JSON structure representing the user settings to save to cloud backup.
* @param {boolean} [overwrite] - (optional) if true, existing settings will be replaced rather than updated. Defaults to false.
* If false, existing settings will be merged with the new settings passed to this function.
* @return {Promise<any>} Will be passed a single object argument which contains the saved settings as a JSON object.
*/
@Cordova({
successIndex: 1,
errorIndex: 2
})
save(settings: any, overwrite?: boolean): Promise<any> {
return;
}
/**
* Loads the current settings.
* @return {Promise<any>} Will be passed a single object argument which contains the saved settings as a JSON object.
*/
@Cordova()
load(): Promise<any> {
return;
}
/**
* Registers a function which will be called if/when settings on the device have been updated from the cloud.
* @param {Function} handler - callback function to invoke when device settings have been updated from the cloud.
*/
@Cordova({ sync: true })
onRestore(handler: Function): void {}
/**
* Outputs verbose log messages from the native plugin components to the JS console.
* @return {Promise<void>}
*/
@Cordova()
enableDebug(): Promise<void> {
return;
}
}