收到通知后,在tabbar项目上设置徽章

时间:2014-11-07 07:04:37

标签: ios push-notification xcode5 uitabbarcontroller badge

我在收到推送通知时尝试为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"];

}

1 个答案:

答案 0 :(得分:4)

我认为您可以使用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信息

相关问题