I've got social network app. App icon badge and tabbar.item badge work fine. But I have a message button in homepage just like instagram. I want this button to show badge when got new message. Here is my Inbox push notification function
// Send Push notification
let pushStr = "\(PFUser.current()![USER_USERNAME]!) sent you a message.:\nRelated post: \(self.adObj[ADS_TITLE]!)"
//\(self.lastMessageStr)
let data = [ "badge" : "Increment",
"alert" : pushStr,
"sound" : "bingbong.aiff"
]
let request = [
"someKey" : self.userObj.objectId!,
"data" : data
] as [String : Any]
PFCloud.callFunction(inBackground: "push", withParameters: request as [String : Any], block: { (results, error) in
if error == nil {
print ("\nPUSH SENT TO: \(self.userObj[USER_USERNAME]!)\nMESSAGE: \(pushStr)\n")
} else {
print ("\(error!.localizedDescription)")
}
})
Here is my chat button in homepageviewcontroller
@IBAction func chatsButt(_ sender: Any) {
if PFUser.current() != nil {
let aVC = storyboard?.instantiateViewController(withIdentifier: "Chats") as! Chats
navigationController?.pushViewController(aVC, animated: true)
} else {
showLoginAlert("You need to be logged in to see your Chats. Want to Login now?")
}
}
When got new message, only message button should show badge, But when got new like, only tab bar item should show badge. How can I do that ?