如何在接收不同索引的通知时更新tabbar徽章值?

时间:2017-02-22 18:29:58

标签: ios swift xcode push-notification

当用户在前景和后台处于不同索引时收到通知时,我想自动更新我的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"
        }
      }
    }
  }

0 个答案:

没有答案