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
- New `color` attribute for Android (Thanks to @Eusebius1920)
- New `quarter` intervall for iOS & 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 #732 loop between update and trigger (Android)
- Fixed #710 crash due to >500 notifications (Android)
......
......@@ -55,52 +55,74 @@ exports.setDefaults = function (newDefaults) {
/**
* Schedule a new local notification.
*
* @param {Object} opts
* @param {Object} msgs
* The notification properties
* @param {Function} callback
* A function to be called after the notification has been canceled
* @param {Object?} scope
* 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) {
this.registerPermission(function(granted) {
exports.schedule = function (msgs, callback, scope, args) {
var fn = function(granted) {
if (!granted)
return;
if (!granted) return;
var notifications = Array.isArray(opts) ? opts : [opts];
var notifications = Array.isArray(msgs) ? msgs : [msgs];
for (var i = 0; i < notifications.length; i++) {
var properties = notifications[i];
var notification = notifications[i];
this.mergeWithDefaults(properties);
this.convertProperties(properties);
this.mergeWithDefaults(notification);
this.convertProperties(notification);
}
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.
*
* @param {Object} options
* @param {Object} notifications
* The notification properties to update
* @param {Function} callback
* A function to be called after the notification has been updated
* @param {Object?} scope
* 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) {
var notifications = Array.isArray(opts) ? opts : [opts];
exports.update = function (msgs, callback, scope, args) {
var fn = function(granted) {
for (var i = 0; i < notifications.length; i++) {
var properties = notifications[i];
if (!granted) return;
this.convertProperties(properties);
}
var notifications = Array.isArray(msgs) ? msgs : [msgs];
for (var i = 0; i < notifications.length; i++) {
var notification = notifications[i];
this.exec('update', notifications, callback, scope);
this.convertProperties(notification);
}
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) {
/**
* Schedule a new local notification.
*
* @param {Object} opts
* @param {Object} notifications
* The notification properties
* @param {Function} callback
* A function to be called after the notification has been canceled
* @param {Object?} scope
* 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) {
this.core.schedule(opts, callback, scope);
exports.schedule = function (notifications, callback, scope, args) {
this.core.schedule(notifications, callback, scope, args);
};
/**
* Update existing notifications specified by IDs in options.
*
* @param {Object} options
* @param {Object} notifications
* The notification properties to update
* @param {Function} callback
* A function to be called after the notification has been updated
* @param {Object?} scope
* 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) {
this.core.update(opts, callback, scope);
exports.update = function (notifications, callback, scope, args) {
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