Commit f5d4d432 by Sebastián Katzer

Notification on iOS will be canceled if a new one with the same ID was added

parent 60b501ab
...@@ -49,6 +49,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331). ...@@ -49,6 +49,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
#### Version 0.7.0 (not yet released) #### Version 0.7.0 (not yet released)
- [bugfix:] App throws an error on iOS if `message` is null. - [bugfix:] App throws an error on iOS if `message` is null.
- [bugfix:] Removed extra line break on iOS if `title` is null or empty. - [bugfix:] Removed extra line break on iOS if `title` is null or empty.
- [bugfix:] Notification on iOS will be canceled if a new one with the same ID was added.
#### Version 0.6.3 (12.12.2013) #### Version 0.6.3 (12.12.2013)
- [bugfix:] Black screen on Android. - [bugfix:] Black screen on Android.
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
@interface APPLocalNotification (Private) @interface APPLocalNotification (Private)
// Entfernt die zur ID passende Meldung
- (void) cancelNotificationWithId:(NSString*)notificationId;
- (NSMutableDictionary*) repeatDict; - (NSMutableDictionary*) repeatDict;
// Alle zusätzlichen Metadaten der Notification als Hash // Alle zusätzlichen Metadaten der Notification als Hash
- (NSDictionary*) userDict:(NSMutableDictionary*)options; - (NSDictionary*) userDict:(NSMutableDictionary*)options;
...@@ -47,23 +49,49 @@ ...@@ -47,23 +49,49 @@
NSArray* arguments = [command arguments]; NSArray* arguments = [command arguments];
NSMutableDictionary* options = [arguments objectAtIndex:0]; NSMutableDictionary* options = [arguments objectAtIndex:0];
UILocalNotification* notification = [self notificationWithProperties:options]; UILocalNotification* notification = [self notificationWithProperties:options];
NSString* notificationId = [notification.userInfo objectForKey:@"id"];
[self cancelNotificationWithId:notificationId];
[[UIApplication sharedApplication] scheduleLocalNotification:notification]; [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}]; }];
} }
/** /**
* Entfernt den anhand der ID angegebenen Eintrag. * Entfernt die zur ID passende Meldung.
*
* @param {NSString} id Die ID der Notification
*/ */
- (void) cancel:(CDVInvokedUrlCommand*)command - (void) cancel:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSArray* arguments = [command arguments]; NSArray* arguments = [command arguments];
NSString* notificationId = [arguments objectAtIndex:0]; NSString* notificationId = [arguments objectAtIndex:0];
[self cancelNotificationWithId:notificationId];
}];
}
/**
* Entfernt alle registrierten Einträge.
*/
- (void) cancelAll:(CDVInvokedUrlCommand*)command
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
/**
* Entfernt die zur ID passende Meldung.
*
* @param {NSString} id Die ID der Notification
*/
- (void) cancelNotificationWithId:(NSString*)notificationId
{
NSArray* notifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; NSArray* notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
if (notificationId == (NSString*)[NSNull null] || [notificationId isEqualToString:@""])
{
return;
}
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications)
{ {
NSString* id = [notification.userInfo objectForKey:@"id"]; NSString* id = [notification.userInfo objectForKey:@"id"];
...@@ -73,15 +101,6 @@ ...@@ -73,15 +101,6 @@
[[UIApplication sharedApplication] cancelLocalNotification:notification]; [[UIApplication sharedApplication] cancelLocalNotification:notification];
} }
} }
}];
}
/**
* Entfernt alle registrierten Einträge.
*/
- (void) cancelAll:(CDVInvokedUrlCommand*)command
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
} }
/** /**
......
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