Commit a21a13bb by Sebastián Katzer

IOS8 support

parent 5b863fbb
## ChangeLog
#### Version 0.8.0 (not yet released)
- [feature:] New method `hasPermission` to ask if the user has granted to display local notifications.
- [feature:] New method `promptForPermission` to promt the user to grant permission to display local notifications.
- [feature:] New Android specific `led:` flag.
- [feature:] Add `isTriggered` & `getTriggeredIds` methods.
- [enhancement:] Android 2.x (SDK >= 7) support (Thanks to **khizarsonu**)
- [enhancement:] Scope parameter for `isScheduled` and `getScheduledIds`
- [enhancement:] Callbacks for `add`, `cancel` & `cancelAll`
- [enhancement:] `image:` accepts remote URLs and local URIs (Android)
- [feature:] New Android specific `led:` flag.
- [feature:] Add `isTriggered` & `getTriggeredIds` methods.
- [enhancement:] __iOS8 Support__
#### Version 0.7.4 (22.03.2014)
- [bugfix:] Platform specific properties were ignored.
......
......@@ -70,12 +70,15 @@ More informations can be found [here][PGB_plugin].
## ChangeLog
#### Version 0.8.0 (not yet released)
- [feature:] New method `hasPermission` to ask if the user has granted to display local notifications.
- [feature:] New method `promptForPermission` to promt the user to grant permission to display local notifications.
- [feature:] New Android specific `led:` flag.
- [feature:] Add `isTriggered` & `getTriggeredIds` methods.
- [enhancement:] Android 2.x (SDK >= 7) support (Thanks to **khizarsonu**)
- [enhancement:] Scope parameter for `isScheduled` and `getScheduledIds`
- [enhancement:] Callbacks for `add`, `cancel` & `cancelAll`
- [enhancement:] `image:` accepts remote URLs and local URIs (Android)
- [feature:] New Android specific `led:` flag
- [feature:] Add `isTriggered` & `getTriggeredIds` methods.
- [enhancement:] __iOS8 Support__
#### Further informations
- See [CHANGELOG.md][changelog] to get the full changelog for the plugin.
......@@ -85,18 +88,20 @@ More informations can be found [here][PGB_plugin].
## Using the plugin
The plugin creates the object ```window.plugin.notification.local``` with the following methods:
1. [notification.local.add][add]
2. [notification.local.cancel][cancel]
3. [notification.local.cancelAll][cancelall]
4. [notification.local.isScheduled][isscheduled]
5. [notification.local.getScheduledIds][getscheduledids]
6. [notification.local.isTriggered][istriggered]
7. [notification.local.getDefaults][getdefaults]
8. [notification.local.setDefaults][setDefaults]
9. [notification.local.onadd][onadd]
10. [notification.local.ontrigger][ontrigger]
11. [notification.local.onclick][onclick]
12. [notification.local.oncancel][oncancel]
1. [notification.local.hasPermission][has_permission]
2. [notification.local.promptForPermission][prompt_for_permission]
3. [notification.local.add][add]
4. [notification.local.cancel][cancel]
5. [notification.local.cancelAll][cancelall]
6. [notification.local.isScheduled][isscheduled]
7. [notification.local.getScheduledIds][getscheduledids]
8. [notification.local.isTriggered][istriggered]
9. [notification.local.getDefaults][getdefaults]
10. [notification.local.setDefaults][setdefaults]
11. [notification.local.onadd][onadd]
12. [notification.local.ontrigger][ontrigger]
13. [notification.local.onclick][onclick]
14. [notification.local.oncancel][oncancel]
### Plugin initialization
The plugin and its methods are not available before the *deviceready* event has been fired.
......@@ -107,6 +112,30 @@ document.addEventListener('deviceready', function () {
}, false);
```
### Determine if the app does have the permission to show local notifications
If the permission has been granted through the user can be retrieved through the `notification.local.hasPermission` interface.<br/>
The method takes a callback function as its argument which will be called with a boolean value. Optional the scope of the callback function ca be defined through a second argument.
#### Further informations
- The method is supported on each platform, however its only relevant for iOS8 and above.
```javascript
window.plugin.notification.local.hasPermission(function (granted) {
// console.log('Permission has been granted: ' + granted);
});
```
### Prompt the user to grant permission for local notifications
The user can be prompted to grant the required permission through the `notification.local.promptForPermission` interface.
#### Further informations
- The method is supported on each platform, however its only relevant for iOS8 and above.
- The user will only get a prompt dialog for the first time. Later its only possible to change the setting via the notification center.
```javascript
window.plugin.notification.local.promptForPermission();
```
### Schedule local notifications
Local notifications can be scheduled through the `notification.local.add` interface.<br>
The method takes a hash as an argument to specify the notification's properties and returns the ID for the notification.<br>
......@@ -533,6 +562,8 @@ This software is released under the [Apache 2.0 License][apache2_license].
[oncancel]: #get-notified-when-a-local-notification-has-been-canceled
[ontrigger]: #get-notified-when-a-local-notification-has-been-triggered
[platform-specific-properties]: #platform-specifics
[has_permission]: #determine-if-the-app-does-have-the-permission-to-show-local-notifications
[prompt_for_permission]: #prompt-the-user-to-grant-permission-for-local-notifications
[add]: #schedule-local-notifications
[cancel]: #cancel-scheduled-local-notifications
[cancelall]: #cancel-all-scheduled-local-notifications
......
......@@ -36,5 +36,9 @@
- (void) isScheduled:(CDVInvokedUrlCommand*)command;
// Retrieves a list of ids from all currently pending notifications
- (void) getScheduledIds:(CDVInvokedUrlCommand*)command;
// Informs if the app has the permission to show notifications
- (void) hasPermission:(CDVInvokedUrlCommand*)command;
// Ask for permission to show notifications
- (void) promptForPermission:(CDVInvokedUrlCommand*)command;
@end
......@@ -20,6 +20,7 @@
*/
#import "APPLocalNotification.h"
#import <Availability.h>
@interface APPLocalNotification ()
......@@ -237,6 +238,51 @@
}];
}
/**
* Informs if the app has the permission to show
* badges and local notifications.
*
* @param callback
* The function to be exec as the callback
*/
- (void) hasPermission:(CDVInvokedUrlCommand *)command
{
[self.commandDelegate runInBackground:^{
CDVPluginResult* result;
BOOL hasPermission = [self hasPermissionToSheduleNotifications];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsBool:hasPermission];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
}
/**
* Ask for permission to show badges.
*
* @param callback
* The function to be exec as the callback
*/
- (void) promptForPermission:(CDVInvokedUrlCommand *)command
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
UIUserNotificationType types;
UIUserNotificationSettings *settings;
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:nil];
[self.commandDelegate runInBackground:^{
[[UIApplication sharedApplication]
registerUserNotificationSettings:settings];
}];
#endif
}
#pragma mark -
#pragma mark Plugin core methods
......@@ -361,6 +407,26 @@
return notification;
}
/**
* If the app has the permission to show badges.
*/
- (BOOL) hasPermissionToSheduleNotifications
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
UIUserNotificationType types;
UIUserNotificationSettings *settings;
settings = [[UIApplication sharedApplication]
currentUserNotificationSettings];
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
return (settings.types & types);
#else
return YES;
#endif
}
#pragma mark -
#pragma mark Plugin delegate and life cycle methods
......
......@@ -144,8 +144,8 @@ LocalNotification.prototype = {
* The notification's ID
*/
add: function (options, callback, scope) {
var options = this.mergeWithDefaults(options),
callbackFn = this.createCallbackFn(callback, scope);
var options = this.mergeWithDefaults(options),
fn = this.createCallbackFn(callback, scope);
if (options.id) {
options.id = options.id.toString();
......@@ -168,12 +168,12 @@ LocalNotification.prototype = {
}
if (['WinCE', 'Win32NT'].indexOf(device.platform) > -1) {
callbackFn = function (cmd) {
fn = function (cmd) {
eval(cmd);
};
}
cordova.exec(callbackFn, null, 'LocalNotification', 'add', [options]);
cordova.exec(fn, null, 'LocalNotification', 'add', [options]);
return options.id;
},
......@@ -189,10 +189,10 @@ LocalNotification.prototype = {
* The scope for the callback function
*/
cancel: function (id, callback, scope) {
var id = id.toString(),
callbackFn = this.createCallbackFn(callback, scope);
var id = id.toString(),
fn = this.createCallbackFn(callback, scope);
cordova.exec(callbackFn, null, 'LocalNotification', 'cancel', [id]);
cordova.exec(fn, null, 'LocalNotification', 'cancel', [id]);
},
/**
......@@ -204,9 +204,9 @@ LocalNotification.prototype = {
* The scope for the callback function
*/
cancelAll: function (callback, scope) {
var callbackFn = this.createCallbackFn(callback, scope);
var fn = this.createCallbackFn(callback, scope);
cordova.exec(callbackFn, null, 'LocalNotification', 'cancelAll', []);
cordova.exec(fn, null, 'LocalNotification', 'cancelAll', []);
},
/**
......@@ -218,9 +218,9 @@ LocalNotification.prototype = {
* The scope for the callback function
*/
getScheduledIds: function (callback, scope) {
var callbackFn = this.createCallbackFn(callback, scope);
var fn = this.createCallbackFn(callback, scope);
cordova.exec(callbackFn, null, 'LocalNotification', 'getScheduledIds', []);
cordova.exec(fn, null, 'LocalNotification', 'getScheduledIds', []);
},
/**
......@@ -234,10 +234,10 @@ LocalNotification.prototype = {
* The scope for the callback function
*/
isScheduled: function (id, callback, scope) {
var id = id.toString(),
callbackFn = this.createCallbackFn(callback, scope);
var id = id.toString(),
fn = this.createCallbackFn(callback, scope);
cordova.exec(callbackFn, null, 'LocalNotification', 'isScheduled', [id]);
cordova.exec(fn, null, 'LocalNotification', 'isScheduled', [id]);
},
/**
......@@ -249,9 +249,9 @@ LocalNotification.prototype = {
* The scope for the callback function
*/
getTriggeredIds: function (callback, scope) {
var callbackFn = this.createCallbackFn(callback, scope);
var fn = this.createCallbackFn(callback, scope);
cordova.exec(callbackFn, null, 'LocalNotification', 'getTriggeredIds', []);
cordova.exec(fn, null, 'LocalNotification', 'getTriggeredIds', []);
},
/**
......@@ -265,10 +265,37 @@ LocalNotification.prototype = {
* The scope for the callback function
*/
isTriggered: function (id, callback, scope) {
var id = id.toString(),
callbackFn = this.createCallbackFn(callback, scope);
var id = id.toString(),
fn = this.createCallbackFn(callback, scope);
cordova.exec(callbackFn, null, 'LocalNotification', 'isTriggered', [id]);
cordova.exec(fn, null, 'LocalNotification', 'isTriggered', [id]);
},
/**
* Informs if the app has the permission to show badges.
*
* @param {Function} callback
* The function to be exec as the callback
* @param {Object?} scope
* The callback function's scope
*/
hasPermission: function (callback, scope) {
var fn = this.createCallbackFn(callback, scope);
if (device.platform == 'iOS') {
cordova.exec(fn, null, 'LocalNotification', 'hasPermission', []);
} else if (fn) {
fn(true);
}
},
/**
* Ask for permission to show badges if not already granted.
*/
promptForPermission: function () {
if (device.platform == 'iOS') {
cordova.exec(null, null, 'LocalNotification', 'promptForPermission', []);
}
},
/**
......
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