Question

I've been struggling with something that seems like it should 'just work' for some time now. I have a push notification set up through Urban Airship and everything works fine EXCEPT for badges updating while the app is in the background. As far as I can tell, as long as badge is set to an integer in the payload this should handle itself if the app is not in the foreground.

If I capture the badge update while the app is in the foreground, I can set it properly, but that isn't the reason I would want to use badges in my app.

Here is my setup in didFinishLaunchingWithOptions:

UAConfig *config = [UAConfig defaultConfig];

    // You can also programatically override the plist values:
    // config.developmentAppKey = @"YourKey";
    // etc.

    // Call takeOff (which creates the UAirship singleton)
    [UAirship takeOff:config];
    [UAPush shared].notificationTypes = (UIRemoteNotificationTypeBadge |
                                         UIRemoteNotificationTypeSound |
                                         UIRemoteNotificationTypeAlert |
                                        UIRemoteNotificationTypeNewsstandContentAvailability);

        [[UAPush shared] setPushEnabled:YES];

    [[UAPush shared] setAutobadgeEnabled:YES];
    [self performSelector:@selector(resetUABadge:)];
    [[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]
                       applicationState:application.applicationState];

The resetUABadge call simply sets everything back to 0 when the app launches. This problem persist whether that performSelector is there or not.

I'm not sure if there is some configuration I'm missing or what, but every other part of the push notification works while the app is backgrounded/closed (alert, sound), but the badge simply will not update.

Was it helpful?

Solution

I found the answer via this question. Turns out if you register for both UIRemoteNotificationTypeBadge and UIRemoteNotificationTypeNewsstandContentAvailability the newsstand type completely breaks badging. Admittedly, I should never have been registered for newsstand in the first place, but I never imagined it would break badging.

Sigh.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top