I have a little problem. I want to set a Badge on a Tab after receiving push but I can't figure out how I can change the badge value (From my AppDelegate)
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
{
print("didReceiveRemoteNotification")
//can't find or access the tabBarItem...
}
I tried different things. One time I get a nil while unwrapping and sometimes I am creating a new TabBarController and I can change the badge Value... But the problem is that it isn't the TabBar which is shown. (First is nil and second is the "new" one)
Here some tries:
let tabBarC = self.storyboard?.instantiateViewControllerWithIdentifier("TC")
let items = tabBarC?.tabBarController?.tabBar.items
let tab = items![3]
tab.badgeValue = "999"
let tabBarController: UITabBarController = storyboard!.instantiateViewControllerWithIdentifier("TC") as! UITabBarController
let tabArray = tabBarController.tabBar.items as NSArray!
let tabItem = tabArray.objectAtIndex(3) as! UITabBarItem
tabItem.badgeValue = "!"
print(tabItem.title)
Ah and my TabBarController isn't my rootViewController
Do you have any suggestions have I can fix this?
Thanks :)