Application icon badge number not increasing : Xcode
I had the same problem and solved it by creating int. variable in class.h
like this :
a custom class.H
@property int badge;
a custom class.M
-(id)init{
_badge=0;
self = [super init];
if (self) {
}
return self;}
-(void)reminderCreator:(NSDate*)onTime withText:(NSString*)text{
_badge += 1;
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = onTime;
localNotification.alertBody = text;
localNotification.soundName=UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber=_badge;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; }
so if you initialize this custom class, somewhere (maybe at your viewController) and then call the reminderCreator method several times to setup few localNotifications, it will assign incremented number to each notification.
+1 if this helped :)
The badge number is set by the operating system when you receive a JSON notification payload that resembles the following:
{
"aps" : {
"alert" : "New notification!",
"badge" : 2
}
}
As you see, it's the server who is responsible for setting the correct number in the badge
key. Your server needs to track or compute the number of pending notifications for each user and generate the badge
number before sending the notification to Apple.
The client responsibility is to clear the notification badge, or decrement it, when the user sees a notification. The code to do so is
application.applicationIconBadgeNumber = application.applicationIconBadgeNumber - 1; // Decrement counter
or
application.applicationIconBadgeNumber = 0; // Reset counter assuming the user is able to see all notifications at once.
you can create a static variable instead, and assign it to the applicationIconBadgeNumber:
static int i=1;
[UIApplication sharedApplication].applicationIconBadgeNumber = i++;