Bot
Bot

Reputation: 31

set badge on tabbar item when notification received

I tried to set badgeValue for UITabBarItem when push notification is received.I am using this code. Here the UITabBarController is not a rootViewController. I tried the same thing in resign active method but there also its not working.

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

  UITabBarController *tabBarController = (UITabBarController *)[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"tabBarController"] ;
  [[tabBarController.tabBar.items objectAtIndex:2] setBadgeValue:@"1"];

}

Upvotes: 3

Views: 4906

Answers (1)

Leo
Leo

Reputation: 24714

I think that you can use NSNotificationCenter to post notification when you received a remoteNotification

In your UITabBarController initialize method

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myNotificationReceived:) name:@"pushNotification" object:nil];

And In myNotificationReceived:

[[self.tabBar.items objectAtIndex:2] setBadgeValue:@"1"];

When you receive a remote notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];

In this way, you can get whole RemoteNotification information

Upvotes: 4

Related Questions