I have an app with push notifications using PHP EasyAPNS notification working fine on Swift 3, iOS 10. But one thing I can't understand is why the badge on TabItem is works fine when I launch the app from the notification alert but not when I open the app direct from the app icon (with the red Badge)
So here is the code that I use on AppDelegate:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [String:Any])
{
print("Message details \(userInfo)")
if let aps = userInfo["aps"] as? NSDictionary
{
if let alertMessage = aps["alert"] as? String {
let rootViewController = self.window?.rootViewController as! UITabBarController!
let tabArray = rootViewController?.tabBar.items as NSArray!
let tabItem = tabArray?.object(at: 3) as! UITabBarItem
tabItem.badgeValue = "1"
let myAlert = UIAlertController(title: "Message", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil)
myAlert.addAction(okAction)
self.window?.rootViewController?.present(myAlert, animated: true, completion: nil)
}
}
}
So, when I click in the alert to open my app, the badge is fine like this:
But when I open the app using the icon itself, the badge is not showing up:
Anyone have any idea what I'm doing wrong?
Please let me know if I can improve the question!