[英]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.