I'm trying to set the badge in my tab bar to "1" on the 4th tab when a notification is received by my app. Strangely enough, my console says that the method is firing (see NSLog "Fire!"), however the badge doesn't appear on my tab bar item once the notification is received? Am I missing something?
AppDelegate.m
-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];
NSLog(@"App notification received!");
// do stuff when app is active
}else{
// do stuff when app is in background
static int i=1;
[UIApplication sharedApplication].applicationIconBadgeNumber = i++;
NSLog(@"App notification received background!");
}
}
ViewController.m
- (void) myNotificationReceived:(NSNotification *) notification {
[[self.tabBarController.tabBar.items objectAtIndex:3] setBadgeValue:@"1"];
NSLog(@"Fire!");
}
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myNotificationReceived:) name:@"pushNotification" object:nil];
}