每當用戶(設備到設備)之間發送郵件時,如果應用程序未處於焦點狀態,接收用戶將收到通知。隨着通知,該標籤的徽章值應增加1在試圖這樣做,我創建了一個通知中心作用,在OneSignal的handleNotificationReceived塊熄滅(內initLaunchWithOptions)像這樣:使用OneSignal從收到的通知中設置徽章值
handleNotificationReceived: { (notification) in
//Notification
NotificationCenter.default.post(name: MESSAGE_NOTIFICATION, object: nil)
print("Received Notification - \(notification?.payload.notificationID ?? "")")
},
和觀察者位於消息傳遞選項卡內與增加標籤欄徽章的函數:
NotificationCenter.default.addObserver(self, selector: #selector(addBadge), name: MESSAGE_NOTIFICATION, object: nil)
//Adds a badge to the messages bar
func addBadge(){
self.navigationController?.tabBarController?.tabBar.items?[3].badgeValue = "1"
if #available(iOS 10.0, *) {
self.navigationController?.tabBarController?.tabBar.items?[3].badgeColor = ChatMessageCell.indexedColor
} else {
// Fallback on earlier versions
}
}
但是,我仍然無法獲得用戶出現的徽章值