Browse Source

Auto increment badge number on iOS

Sebastián Katzer 11 years ago
parent
commit
ebbfc4d0d9

+ 2 - 2
src/ios/APPLocalNotification.m

@@ -360,7 +360,6 @@
  */
 - (void) didReceiveLocalNotification:(NSNotification*)localNotification
 {
-    UIApplication* app = [UIApplication sharedApplication];
     UILocalNotification* notification = [localNotification object];
 
     BOOL autoCancel = notification.options.autoCancel;
@@ -368,7 +367,8 @@
 
     NSString* event = (timeInterval <= 1 && deviceready) ? @"trigger" : @"click";
 
-    app.applicationIconBadgeNumber -= 1;
+    [UIApplication sharedApplication]
+    .applicationIconBadgeNumber -= 1;
 
     [self fireEvent:event localNotification:notification];
 

+ 7 - 1
src/ios/APPLocalNotificationOptions.m

@@ -101,7 +101,13 @@
  */
 - (NSInteger) badgeNumber
 {
-    return [[dict objectForKey:@"badge"] intValue];
+    NSInteger number = [[dict objectForKey:@"badge"] intValue];
+
+    if (number == -1) {
+        number = 1 + [UIApplication sharedApplication].applicationIconBadgeNumber;
+    }
+
+    return number;
 }
 
 #pragma mark -

+ 1 - 1
www/local-notification.js

@@ -64,7 +64,7 @@ exports._defaults = {
     message:    '',
     title:      '',
     autoCancel: false,
-    badge:      0,
+    badge:      -1,
     id:         '0',
     json:       '',
     repeat:     ''