Loading README.md +18 −0 Changes for README.md: 18 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -58,6 +58,8 @@ More informations can be found [here](https://build.phonegap.com/plugins/413). - [bugfix:] Callbacks for non-repeating notifications were not called if they were not created in the current app instance on iOS. - [enhancement:] Added 'secondly' and 'minutely' as new repeat time aliases. - [bugfix:] `sound:null` didnt work for Android. The default sound was played. - [feature:] New interface `isScheduled` to check wether a notification with an ID is pending. - [feature:] New interface `getScheduledIds` to retrieve a list with all currently pending notifications. #### Version 0.7.2 (09.02.2014) - [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**. Loading Loading @@ -178,6 +180,22 @@ window.plugin.notification.local.on_callback_ = function (id, state, json) {}; ``` **Note:** The *ontrigger* callback is only invoked in background if the app is not suspended! ### isScheduled() Checks wether a notification with an ID is scheduled. It takes the ID as an argument and a callback function to be called with the result. ```javascript window.plugin.notification.local.isScheduled(id, function (isScheduled) { }); ``` ### getScheduledIds() Checks wether a notification with an ID is scheduled. It takes a callback function to be called with the result as an array. ```javascript window.plugin.notification.local.getScheduledIds(function (pendingIds) { }); ``` ### getDefaults() Gives an overview about all available notification properties for the platform and their default values. The function returns an object. ```javascript Loading src/android/LocalNotification.java +45 −0 Changes for src/android/LocalNotification.java: 45 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CordovaWebView; import org.apache.cordova.PluginResult; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; Loading Loading @@ -107,6 +108,20 @@ public class LocalNotification extends CordovaPlugin { return true; } if (action.equalsIgnoreCase("isScheduled")) { String id = args.optString(0); isScheduled(id, callbackContext); return true; } if (action.equalsIgnoreCase("getScheduledIds")) { getScheduledIds(callbackContext); return true; } // Returning false results in a "MethodNotFound" error. return false; } Loading Loading @@ -187,6 +202,36 @@ public class LocalNotification extends CordovaPlugin { nc.cancelAll(); } /** * Checks wether a notification with an ID is scheduled. * * @param id * The notification ID to be check. * @param callbackContext */ public static void isScheduled (String id, CallbackContext callbackContext) { SharedPreferences settings = getSharedPreferences(); Map<String, ?> alarms = settings.getAll(); boolean isScheduled = alarms.containsKey(id); PluginResult result = new PluginResult(PluginResult.Status.OK, isScheduled); callbackContext.sendPluginResult(result); } /** * Retrieves a list with all currently pending notifications. * * @param callbackContext */ public static void getScheduledIds (CallbackContext callbackContext) { SharedPreferences settings = getSharedPreferences(); Map<String, ?> alarms = settings.getAll(); Set<String> alarmIds = alarms.keySet(); JSONArray pendingIds = new JSONArray(alarmIds); callbackContext.success(pendingIds); } /** * Persist the information of this alarm to the Android Shared Preferences. * This will allow the application to restore the alarm upon device reboot. Loading src/ios/APPLocalNotification.h +4 −0 Changes for src/ios/APPLocalNotification.h: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -35,5 +35,9 @@ extern NSString *const kAPP_LOCALNOTIFICATION; - (void) cancel:(CDVInvokedUrlCommand*)command; // Entfernt alle registrierten Einträge - (void) cancelAll:(CDVInvokedUrlCommand*)command; // Checks wether a notification with an ID is scheduled - (void) isScheduled:(CDVInvokedUrlCommand*)command; // Retrieves a list with all currently pending notifications - (void) getScheduledIds:(CDVInvokedUrlCommand*)command; @end src/ios/APPLocalNotification.m +47 −0 Changes for src/ios/APPLocalNotification.m: 47 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -110,6 +110,53 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; }]; } /** * Checks wether a notification with an ID is scheduled. */ - (void) isScheduled:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ CDVPluginResult* result; NSArray* arguments = [command arguments]; NSString* id = [arguments objectAtIndex:0]; NSString* key = [kAPP_LOCALNOTIFICATION stringByAppendingString:id]; NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:key]; bool isScheduled = data != NULL; result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:isScheduled]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; }]; } /** * Retrieves a list with all currently pending notifications. */ - (void) getScheduledIds:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ NSMutableArray* scheduledIds = [[NSMutableArray alloc] init]; NSDictionary* entries = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; CDVPluginResult* result; for (NSString* key in [entries allKeys]) { if ([key hasPrefix:kAPP_LOCALNOTIFICATION]) { NSString* id = [key stringByReplacingOccurrencesOfString:kAPP_LOCALNOTIFICATION withString:@""]; [scheduledIds addObject:id]; } } result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:scheduledIds]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; }]; } /** * Entfernt den zur ID passenden Eintrag. * Loading src/wp8/LocalNotification.cs +16 −0 Changes for src/wp8/LocalNotification.cs: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -106,6 +106,22 @@ namespace Cordova.Extension.Commands DispatchCommandResult(); } /// <summary> /// Checks wether a notification with an ID is scheduled /// </summary> public void isScheduled (string jsonArgs) { DispatchCommandResult(); } /// <summary> /// Retrieves a list with all currently pending notifications /// </summary> public void getScheduledIds (string jsonArgs) { DispatchCommandResult(); } /// <summary> /// Creates tile data /// </summary> Loading Loading
README.md +18 −0 Changes for README.md: 18 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -58,6 +58,8 @@ More informations can be found [here](https://build.phonegap.com/plugins/413). - [bugfix:] Callbacks for non-repeating notifications were not called if they were not created in the current app instance on iOS. - [enhancement:] Added 'secondly' and 'minutely' as new repeat time aliases. - [bugfix:] `sound:null` didnt work for Android. The default sound was played. - [feature:] New interface `isScheduled` to check wether a notification with an ID is pending. - [feature:] New interface `getScheduledIds` to retrieve a list with all currently pending notifications. #### Version 0.7.2 (09.02.2014) - [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**. Loading Loading @@ -178,6 +180,22 @@ window.plugin.notification.local.on_callback_ = function (id, state, json) {}; ``` **Note:** The *ontrigger* callback is only invoked in background if the app is not suspended! ### isScheduled() Checks wether a notification with an ID is scheduled. It takes the ID as an argument and a callback function to be called with the result. ```javascript window.plugin.notification.local.isScheduled(id, function (isScheduled) { }); ``` ### getScheduledIds() Checks wether a notification with an ID is scheduled. It takes a callback function to be called with the result as an array. ```javascript window.plugin.notification.local.getScheduledIds(function (pendingIds) { }); ``` ### getDefaults() Gives an overview about all available notification properties for the platform and their default values. The function returns an object. ```javascript Loading
src/android/LocalNotification.java +45 −0 Changes for src/android/LocalNotification.java: 45 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CordovaWebView; import org.apache.cordova.PluginResult; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; Loading Loading @@ -107,6 +108,20 @@ public class LocalNotification extends CordovaPlugin { return true; } if (action.equalsIgnoreCase("isScheduled")) { String id = args.optString(0); isScheduled(id, callbackContext); return true; } if (action.equalsIgnoreCase("getScheduledIds")) { getScheduledIds(callbackContext); return true; } // Returning false results in a "MethodNotFound" error. return false; } Loading Loading @@ -187,6 +202,36 @@ public class LocalNotification extends CordovaPlugin { nc.cancelAll(); } /** * Checks wether a notification with an ID is scheduled. * * @param id * The notification ID to be check. * @param callbackContext */ public static void isScheduled (String id, CallbackContext callbackContext) { SharedPreferences settings = getSharedPreferences(); Map<String, ?> alarms = settings.getAll(); boolean isScheduled = alarms.containsKey(id); PluginResult result = new PluginResult(PluginResult.Status.OK, isScheduled); callbackContext.sendPluginResult(result); } /** * Retrieves a list with all currently pending notifications. * * @param callbackContext */ public static void getScheduledIds (CallbackContext callbackContext) { SharedPreferences settings = getSharedPreferences(); Map<String, ?> alarms = settings.getAll(); Set<String> alarmIds = alarms.keySet(); JSONArray pendingIds = new JSONArray(alarmIds); callbackContext.success(pendingIds); } /** * Persist the information of this alarm to the Android Shared Preferences. * This will allow the application to restore the alarm upon device reboot. Loading
src/ios/APPLocalNotification.h +4 −0 Changes for src/ios/APPLocalNotification.h: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -35,5 +35,9 @@ extern NSString *const kAPP_LOCALNOTIFICATION; - (void) cancel:(CDVInvokedUrlCommand*)command; // Entfernt alle registrierten Einträge - (void) cancelAll:(CDVInvokedUrlCommand*)command; // Checks wether a notification with an ID is scheduled - (void) isScheduled:(CDVInvokedUrlCommand*)command; // Retrieves a list with all currently pending notifications - (void) getScheduledIds:(CDVInvokedUrlCommand*)command; @end
src/ios/APPLocalNotification.m +47 −0 Changes for src/ios/APPLocalNotification.m: 47 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -110,6 +110,53 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; }]; } /** * Checks wether a notification with an ID is scheduled. */ - (void) isScheduled:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ CDVPluginResult* result; NSArray* arguments = [command arguments]; NSString* id = [arguments objectAtIndex:0]; NSString* key = [kAPP_LOCALNOTIFICATION stringByAppendingString:id]; NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:key]; bool isScheduled = data != NULL; result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:isScheduled]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; }]; } /** * Retrieves a list with all currently pending notifications. */ - (void) getScheduledIds:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ NSMutableArray* scheduledIds = [[NSMutableArray alloc] init]; NSDictionary* entries = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; CDVPluginResult* result; for (NSString* key in [entries allKeys]) { if ([key hasPrefix:kAPP_LOCALNOTIFICATION]) { NSString* id = [key stringByReplacingOccurrencesOfString:kAPP_LOCALNOTIFICATION withString:@""]; [scheduledIds addObject:id]; } } result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:scheduledIds]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; }]; } /** * Entfernt den zur ID passenden Eintrag. * Loading
src/wp8/LocalNotification.cs +16 −0 Changes for src/wp8/LocalNotification.cs: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -106,6 +106,22 @@ namespace Cordova.Extension.Commands DispatchCommandResult(); } /// <summary> /// Checks wether a notification with an ID is scheduled /// </summary> public void isScheduled (string jsonArgs) { DispatchCommandResult(); } /// <summary> /// Retrieves a list with all currently pending notifications /// </summary> public void getScheduledIds (string jsonArgs) { DispatchCommandResult(); } /// <summary> /// Creates tile data /// </summary> Loading