Set icon to tab element when notification is received
I tried to set badgeValue for UITabBarItem
when push notification is received. I am using this code. There is UITabBarController
no rootViewController here. I've tried the same in humble active mode but doesn't work there either.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UITabBarController *tabBarController = (UITabBarController *)[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"tabBarController"] ;
[[tabBarController.tabBar.items objectAtIndex:2] setBadgeValue:@"1"];
}
+3
source to share
1 answer
I think you can use NSNotificationCenter to send notifications when you received remoteNotification
In your UITabBarController
initialize method
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myNotificationReceived:) name:@"pushNotification" object:nil];
A B myNotificationReceived:
[[self.tabBar.items objectAtIndex:2] setBadgeValue:@"1"];
When you receive a remote notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];
This way you can get all RemoteNotification information
+3
source to share