Doesn't set badge number to match aps value in iOS #19

Closed
drmike0099 opened this Issue Dec 10, 2012 · 1 comment

2 participants

@drmike0099

The PushNotification.m code as-is does not set the badge number due to two reasons:
1) It sends data to the JS code, however the badge number is not part of that data, only the message and the extras that go along with it.
2) It explicitly sets the badge to 0 when receiving a notification, and ignores the aps value.

The below code from PushNotification.m shows both of these:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
     UALOG(@"PushNotificationPlugin: Received remote notification: %@", userInfo);

     [[UAPush shared] handleNotification:userInfo applicationState:application.applicationState];
     [[UAPush shared] setBadgeNumber:0]; // zero badge after push received

    NSString *alert = [self alertForUserInfo:userInfo];
    NSMutableDictionary *extras = [self extrasForUserInfo:userInfo];

    [self raisePush:alert withExtras:extras];
}

Rather than attempt to handle in JS, I made the change so that PushNotification.m sets the badge number, as shown below.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    UALOG(@"PushNotificationPlugin: Received remote notification: %@", userInfo);

    [[UAPush shared] handleNotification:userInfo applicationState:application.applicationState];
    //[[UAPush shared] setBadgeNumber:0]; // zero badge after push received
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    NSNumber *newBadgeNum = [apsInfo objectForKey:@"badge"];
    int theValue = [newBadgeNum intValue];
    [[UAPush shared] setBadgeNumber:theValue]; // set badge number to what is sent in the userInfo

    NSString *alert = [self alertForUserInfo:userInfo];
    NSMutableDictionary *extras = [self extrasForUserInfo:userInfo];

    [self raisePush:alert withExtras:extras];
}

Note: I am definitely not an iOS programmer, so the above just gets it working, but I imagine requires other code to make it robust.

@rlepinski

We only reset the badge on app start or receiving notification in foreground in the new release.

@rlepinski rlepinski closed this Jul 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment