Krishna Raj Salim
Krishna Raj Salim

Reputation: 7390

Fetch the integer value of badge(from push notification) : Xcode

In one of my apps, I want to fetch the integer value of badge(from push notification) programmatically.

edit: Inside 'application didReceiveRemoteNotification', I have to set:

badge No. = existing badge No. + 1. 

And, how to find this existing badge No.? Can anyone help...?

Thanks in advance...

Upvotes: 2

Views: 1334

Answers (2)

Anurag Sharma
Anurag Sharma

Reputation: 4855

Here is a bit accurate for what you are looking for

Do this in appdelegate.m ---> in didfinishlaunching method :

NSString *badgeCount = [NSString stringWithFormat:@"%li", (long)[[UIApplication sharedApplication] applicationIconBadgeNumber]];
NSInteger countNumber = [badgeCount intValue];

Or if you want to set 0 initially:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
//this will set 0 to initial badge no 

Upvotes: 0

Kyle Fang
Kyle Fang

Reputation: 1209

[UIApplication sharedApplication].applicationIconBadgeNumber

is that what you looking for?

for the badge number in APN just arrived.

in AppDelegate

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSDictionary *notification = [userInfo objectForKey:@"aps"];
    //notification is what you want. print it to find out the details. 
    //Title, Badge Count and all that
}

Upvotes: 2

Related Questions