当用户在前景和后台处于不同索引时收到通知时,我想自动更新我的tabbar徽章值。我尝试使用以下代码,但它不起作用,请让我知道可能性
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
pushDictionary = userInfo
NSNotificationCenter.defaultCenter().postNotificationName("PushNotification", object: self, userInfo: userInfo)
let pushNotification = PushNotification(dictionary: pushDictionary!)
notification.subtitleText = pushNotification.message
if application.applicationState == UIApplicationState.Inactive {
if pushNotification.type != nil {
if pushNotification.type == "feed" {
self.tabBarController?.tabBar.items![0].badgeValue = "1"
}
if pushNotification.type == "message" {
self.tabBarController?.tabBar.items![1].badgeValue = "1"
}
}
}
}