My app is based on creating the new event. Whenever the new event created by any member all devices get push notification for the new event. For that I had set the badge number on the Event button.
It is working fine when app is running but the delegate method doesn't work when the app is inactive or in background mode.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if(application.applicationState == UIApplicationStateInactive)
{
NSLog(@"inactive");
}
else if (application.applicationState == UIApplicationStateActive)
{
NSLog(@"active");
}
else
{
NSLog(@"background");
}
NSString *badgenum=[[NSUserDefaults standardUserDefaults]objectForKey:@"eventbadges"];
NSString *badgestr = [NSString stringWithFormat:@"%d",[badgenum intValue]+1];
[[NSUserDefaults standardUserDefaults]setObject:badgestr forKey:@"eventbadges"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"updatebadges" object:self];
}