Whenever a message is sent between users (device to device), the receiving user gets a notification if the app is not in focus. Along with the notification, the badge value for that tab should increase by 1. In an attempt to do so, I've created a NotificationCenter action that goes off in OneSignal's handleNotificationReceived block (within initLaunchWithOptions) like so:
handleNotificationReceived: { (notification) in
//Notification
NotificationCenter.default.post(name: MESSAGE_NOTIFICATION, object: nil)
print("Received Notification - \(notification?.payload.notificationID ?? "")")
},
and the observer is located within the Messaging tab with a function that increases the tab bar badge:
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
}
}
However, Im still not able to get the badge value for the user to appear