[英]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. 当收到推送通知时,我尝试为UITabBarItem
设置badgeValue。我正在使用此代码。 Here the UITabBarController
is not a rootViewController. 这里的UITabBarController
不是rootViewController。 I tried the same thing in resign active method but there also its not working. 我在resign active方法中尝试过同样的事情但是它也没有用。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UITabBarController *tabBarController = (UITabBarController *)[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"tabBarController"] ;
[[tabBarController.tabBar.items objectAtIndex:2] setBadgeValue:@"1"];
}
I think that you can use NSNotificationCenter to post notification when you received a remoteNotification 我认为您可以使用NSNotificationCenter在收到remoteNotification时发布通知
In your UITabBarController
initialize method 在你的UITabBarController
初始化方法中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myNotificationReceived:) name:@"pushNotification" object:nil];
And In myNotificationReceived:
并在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 通过这种方式,您可以获得整个RemoteNotification信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.