N S
N S

Reputation: 2603

Push notification badges not appearing?

I'm using Urban Airship to send push notifications to my app

eg:

{"aps": {"badge": 2, "alert": "Part 2 of the August Issue is ready to download!", "sound": "default"}, "device_tokens": ["X"]}

The alert will display perfectly, however the app icon is never badged regardless of what I set "badge":# to...

Is my payload incorrect or is there extra code I'm supposed to add to my app to handle badges as well as alerts? Thanks!

EDIT: I'm registering for push notifications like this:

// Register for notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];

Upvotes: 4

Views: 4263

Answers (3)

Jiraheta
Jiraheta

Reputation: 481

I was running with a similar problem. After a few minutes of checking around. I notice that there was a problem with my server side code. I found out that badge value has to be implicitly set as an integer to get the desired result. Hope that helps anyone reading this.

Upvotes: 6

Muhammed Sadiq.HS
Muhammed Sadiq.HS

Reputation: 773

set the following code in the appdelegate .m file..

-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{


    NSLog(@"Received notification: %@", userInfo);
    //[self addMessageFromRemoteNotification:userInfo];

    NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"];
    NSLog(@"my message-- %@",alertValue);
    int badgeValue= [alertValue intValue];

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];

}

Upvotes: 2

logancautrell
logancautrell

Reputation: 8772

In iOS 5 there is a Settings -> Notifications. Double check that the Badge App Icon is turned on.

I assume that the app is not in the foreground when you were testing? It if is in the foreground then you have to handle badging manually.

Upvotes: 2

Related Questions