Commit f0ca49c4 by Sebastián Katzer

Fixes #634 Option to skip permission check

parent 731ac9df
...@@ -7,7 +7,9 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo ...@@ -7,7 +7,9 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo
- New `color` attribute for Android (Thanks to @Eusebius1920) - New `color` attribute for Android (Thanks to @Eusebius1920)
- New `quarter` intervall for iOS & Android - New `quarter` intervall for iOS & Android
- Made small icon optional (Android) - Made small icon optional (Android)
- Windows platform does not use hooks anymore - Windows platform works without hooks
- `update` checks for permission like `schedule`
- Fixed #634 option to skip permission check
- Fixed #588 crash when basename & extension can't be extracted (Android) - Fixed #588 crash when basename & extension can't be extracted (Android)
- Fixed #732 loop between update and trigger (Android) - Fixed #732 loop between update and trigger (Android)
- Fixed #710 crash due to >500 notifications (Android) - Fixed #710 crash due to >500 notifications (Android)
......
...@@ -55,52 +55,74 @@ exports.setDefaults = function (newDefaults) { ...@@ -55,52 +55,74 @@ exports.setDefaults = function (newDefaults) {
/** /**
* Schedule a new local notification. * Schedule a new local notification.
* *
* @param {Object} opts * @param {Object} msgs
* The notification properties * The notification properties
* @param {Function} callback * @param {Function} callback
* A function to be called after the notification has been canceled * A function to be called after the notification has been canceled
* @param {Object?} scope * @param {Object?} scope
* The scope for the callback function * The scope for the callback function
* @param {Object?} args
* skipPermission:true schedules the notifications immediatly without
* registering or checking for permission
*/ */
exports.schedule = function (opts, callback, scope) { exports.schedule = function (msgs, callback, scope, args) {
this.registerPermission(function(granted) { var fn = function(granted) {
if (!granted) if (!granted) return;
return;
var notifications = Array.isArray(opts) ? opts : [opts]; var notifications = Array.isArray(msgs) ? msgs : [msgs];
for (var i = 0; i < notifications.length; i++) { for (var i = 0; i < notifications.length; i++) {
var properties = notifications[i]; var notification = notifications[i];
this.mergeWithDefaults(properties); this.mergeWithDefaults(notification);
this.convertProperties(properties); this.convertProperties(notification);
} }
this.exec('schedule', notifications, callback, scope); this.exec('schedule', notifications, callback, scope);
}, this); };
if (args && args.skipPermission) {
fn.call(this, true);
} else {
this.registerPermission(fn, this);
}
}; };
/** /**
* Update existing notifications specified by IDs in options. * Update existing notifications specified by IDs in options.
* *
* @param {Object} options * @param {Object} notifications
* The notification properties to update * The notification properties to update
* @param {Function} callback * @param {Function} callback
* A function to be called after the notification has been updated * A function to be called after the notification has been updated
* @param {Object?} scope * @param {Object?} scope
* The scope for the callback function * The scope for the callback function
* @param {Object?} args
* skipPermission:true schedules the notifications immediatly without
* registering or checking for permission
*/ */
exports.update = function (opts, callback, scope) { exports.update = function (msgs, callback, scope, args) {
var notifications = Array.isArray(opts) ? opts : [opts]; var fn = function(granted) {
if (!granted) return;
var notifications = Array.isArray(msgs) ? msgs : [msgs];
for (var i = 0; i < notifications.length; i++) { for (var i = 0; i < notifications.length; i++) {
var properties = notifications[i]; var notification = notifications[i];
this.convertProperties(properties); this.convertProperties(notification);
} }
this.exec('update', notifications, callback, scope); this.exec('update', notifications, callback, scope);
};
if (args && args.skipPermission) {
fn.call(this, true);
} else {
this.registerPermission(fn, this);
}
}; };
/** /**
......
...@@ -47,29 +47,35 @@ exports.setDefaults = function (defaults) { ...@@ -47,29 +47,35 @@ exports.setDefaults = function (defaults) {
/** /**
* Schedule a new local notification. * Schedule a new local notification.
* *
* @param {Object} opts * @param {Object} notifications
* The notification properties * The notification properties
* @param {Function} callback * @param {Function} callback
* A function to be called after the notification has been canceled * A function to be called after the notification has been canceled
* @param {Object?} scope * @param {Object?} scope
* The scope for the callback function * The scope for the callback function
* @param {Object?} args
* skipPermission:true schedules the notifications immediatly without
* registering or checking for permission
*/ */
exports.schedule = function (opts, callback, scope) { exports.schedule = function (notifications, callback, scope, args) {
this.core.schedule(opts, callback, scope); this.core.schedule(notifications, callback, scope, args);
}; };
/** /**
* Update existing notifications specified by IDs in options. * Update existing notifications specified by IDs in options.
* *
* @param {Object} options * @param {Object} notifications
* The notification properties to update * The notification properties to update
* @param {Function} callback * @param {Function} callback
* A function to be called after the notification has been updated * A function to be called after the notification has been updated
* @param {Object?} scope * @param {Object?} scope
* The scope for the callback function * The scope for the callback function
* @param {Object?} args
* skipPermission:true schedules the notifications immediatly without
* registering or checking for permission
*/ */
exports.update = function (opts, callback, scope) { exports.update = function (notifications, callback, scope, args) {
this.core.update(opts, callback, scope); this.core.update(notifications, callback, scope, args);
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment