ios - 收到通知时在标签栏项目上设置角标(Badge)

标签 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"];

}

最佳答案

我认为您可以在收到 remoteNotification 时使用 NSNotificationCenter 发布通知

在你的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信息

关于ios - 收到通知时在标签栏项目上设置角标(Badge),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26795868/

相关文章:

ios - 为 SpriteKit 中的函数添加延迟

ios - 当我第一次打开应用程序时,我的导航栏字体不会更改为我的自定义字体

android - 如何在android中更改通知栏的字符串区域设置

localization - Xcode 5- Storyboard的本地化

ios - xcode 5 本地化失败

ios - UITableViewCell textLabel 颜色不变

ios - 使用 swift 通过 http POST 安全地发送信用卡详细信息是否安全?

android-layout - 显示股票行情文字而不通知

objective-c - 推送通知委托(delegate)方法问题

ios - 如何在Xcode 5中安装文档集?