[英]set badge on tabbar item when notification received
当收到推送通知时,我尝试为UITabBarItem
设置badgeValue。我正在使用此代码。 这里的UITabBarController
不是rootViewController。 我在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"];
}
我认为您可以使用NSNotificationCenter在收到remoteNotification时发布通知
在你的UITabBarController
初始化方法中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myNotificationReceived:) name:@"pushNotification" object:nil];
并在myNotificationReceived:
[[self.tabBar.items objectAtIndex:2] setBadgeValue:@"1"];
收到远程通知时
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];
通过这种方式,您可以获得整个RemoteNotification信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.