|
|
@@ -58,10 +58,14 @@ LocalNotification.prototype = {
|
|
|
|
|
|
/**
|
|
|
* @private
|
|
|
- * Merge settings with default values
|
|
|
+ *
|
|
|
+ * Merges custom properties with the default values.
|
|
|
*
|
|
|
* @param {Object} options
|
|
|
+ * Set of custom values
|
|
|
+ *
|
|
|
* @retrun {Object}
|
|
|
+ * The merged property list
|
|
|
*/
|
|
|
mergeWithDefaults: function (options) {
|
|
|
var defaults = this.getDefaults();
|
|
|
@@ -77,6 +81,11 @@ LocalNotification.prototype = {
|
|
|
|
|
|
/**
|
|
|
* @private
|
|
|
+ *
|
|
|
+ * Merges the platform specific properties into the default properties.
|
|
|
+ *
|
|
|
+ * @return {Object}
|
|
|
+ * The default properties for the platform
|
|
|
*/
|
|
|
applyPlatformSpecificOptions: function () {
|
|
|
var defaults = this._defaults;
|
|
|
@@ -94,13 +103,18 @@ LocalNotification.prototype = {
|
|
|
defaults.image = null;
|
|
|
defaults.wideImage = null;
|
|
|
};
|
|
|
+
|
|
|
+ return defaults;
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* Add a new entry to the registry
|
|
|
*
|
|
|
* @param {Object} options
|
|
|
- * @return {Number} The notification's ID
|
|
|
+ * The notification properties
|
|
|
+ *
|
|
|
+ * @return {Number}
|
|
|
+ * The notification's ID
|
|
|
*/
|
|
|
add: function (options) {
|
|
|
var options = this.mergeWithDefaults(options),
|
|
|
@@ -130,77 +144,93 @@ LocalNotification.prototype = {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * Cancels the specified notification
|
|
|
+ * Cancels the specified notification.
|
|
|
*
|
|
|
- * @param {String} id of the notification
|
|
|
+ * @param {String} id
|
|
|
+ * The ID of the notification
|
|
|
*/
|
|
|
cancel: function (id) {
|
|
|
- cordova.exec(null, null, 'LocalNotification', 'cancel', [id.toString()]);
|
|
|
+ var id = id.toString();
|
|
|
+
|
|
|
+ cordova.exec(null, null, 'LocalNotification', 'cancel', [id]);
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * Removes all previously registered notifications
|
|
|
+ * Removes all previously registered notifications.
|
|
|
*/
|
|
|
cancelAll: function () {
|
|
|
cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * @async
|
|
|
- *
|
|
|
* Retrieves a list with all currently pending notifications.
|
|
|
*
|
|
|
* @param {Function} callback
|
|
|
+ * A callback function to be called with the list
|
|
|
*/
|
|
|
getScheduledIds: function (callback) {
|
|
|
cordova.exec(callback, null, 'LocalNotification', 'getScheduledIds', []);
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * @async
|
|
|
- *
|
|
|
* Checks wether a notification with an ID is scheduled.
|
|
|
*
|
|
|
- * @param {String} id
|
|
|
+ * @param {String} id
|
|
|
+ * The ID of the notification
|
|
|
* @param {Function} callback
|
|
|
+ * A callback function to be called with the list
|
|
|
*/
|
|
|
isScheduled: function (id, callback) {
|
|
|
- cordova.exec(callback, null, 'LocalNotification', 'isScheduled', [id.toString()]);
|
|
|
+ var id = id.toString();
|
|
|
+
|
|
|
+ cordova.exec(callback, null, 'LocalNotification', 'isScheduled', [id]);
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* Occurs when a notification was added.
|
|
|
*
|
|
|
- * @param {String} id The ID of the notification
|
|
|
- * @param {String} state Either "foreground" or "background"
|
|
|
- * @param {String} json A custom (JSON) string
|
|
|
+ * @param {String} id
|
|
|
+ * The ID of the notification
|
|
|
+ * @param {String} state
|
|
|
+ * Either "foreground" or "background"
|
|
|
+ * @param {String} json
|
|
|
+ * A custom (JSON) string
|
|
|
*/
|
|
|
onadd: function (id, state, json) {},
|
|
|
|
|
|
/**
|
|
|
* Occurs when the notification is triggered.
|
|
|
*
|
|
|
- * @param {String} id The ID of the notification
|
|
|
- * @param {String} state Either "foreground" or "background"
|
|
|
- * @param {String} json A custom (JSON) string
|
|
|
+ * @param {String} id
|
|
|
+ * The ID of the notification
|
|
|
+ * @param {String} state
|
|
|
+ * Either "foreground" or "background"
|
|
|
+ * @param {String} json
|
|
|
+ * A custom (JSON) string
|
|
|
*/
|
|
|
ontrigger: function (id, state, json) {},
|
|
|
|
|
|
/**
|
|
|
* Fires after the notification was clicked.
|
|
|
*
|
|
|
- * @param {String} id The ID of the notification
|
|
|
- * @param {String} state Either "foreground" or "background"
|
|
|
- * @param {String} json A custom (JSON) string
|
|
|
+ * @param {String} id
|
|
|
+ * The ID of the notification
|
|
|
+ * @param {String} state
|
|
|
+ * Either "foreground" or "background"
|
|
|
+ * @param {String} json
|
|
|
+ * A custom (JSON) string
|
|
|
*/
|
|
|
onclick: function (id, state, json) {},
|
|
|
|
|
|
/**
|
|
|
* Fires if the notification was canceled.
|
|
|
*
|
|
|
- * @param {String} id The ID of the notification
|
|
|
- * @param {String} state Either "foreground" or "background"
|
|
|
- * @param {String} json A custom (JSON) string
|
|
|
+ * @param {String} id
|
|
|
+ * The ID of the notification
|
|
|
+ * @param {String} state
|
|
|
+ * Either "foreground" or "background"
|
|
|
+ * @param {String} json
|
|
|
+ * A custom (JSON) string
|
|
|
*/
|
|
|
oncancel: function (id, state, json) {}
|
|
|
};
|
|
|
@@ -208,24 +238,32 @@ LocalNotification.prototype = {
|
|
|
var plugin = new LocalNotification(),
|
|
|
channel = require('cordova/channel');
|
|
|
|
|
|
+// Called after all 'deviceready' listener are called
|
|
|
channel.deviceready.subscribe( function () {
|
|
|
+ // Device is ready now, the listeners are registered and all queued events
|
|
|
+ // can be executed now.
|
|
|
cordova.exec(null, null, 'LocalNotification', 'deviceready', []);
|
|
|
});
|
|
|
|
|
|
channel.onCordovaReady.subscribe( function () {
|
|
|
+ // The cordova device plugin is ready now
|
|
|
channel.onCordovaInfoReady.subscribe( function () {
|
|
|
if (device.platform == 'Android') {
|
|
|
channel.onPause.subscribe( function () {
|
|
|
+ // Necessary to set the state to `background`
|
|
|
cordova.exec(null, null, 'LocalNotification', 'pause', []);
|
|
|
});
|
|
|
|
|
|
channel.onResume.subscribe( function () {
|
|
|
+ // Necessary to set the state to `foreground`
|
|
|
cordova.exec(null, null, 'LocalNotification', 'resume', []);
|
|
|
});
|
|
|
|
|
|
+ // Necessary to set the state to `foreground`
|
|
|
cordova.exec(null, null, 'LocalNotification', 'resume', []);
|
|
|
}
|
|
|
|
|
|
+ // Merges the platform specific properties into the default properties
|
|
|
plugin.applyPlatformSpecificOptions();
|
|
|
});
|
|
|
});
|