我有一個使用PHP EasyAPNS通知的推送通知的應用程序,可以在Swift 3,iOS 10上正常工作。但有一件事我不明白爲什麼徽章只有當我從通知觸發器啓動應用程序時才顯示帶有BadgeValue的TabItem
:在TabItem的是,當我從通知警報啓動應用程序,但不是當我打開該應用從應用程序圖標直接(與紅色徽章)因此,這裏是我的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)
}
}
}
所以,當我點擊警報來打開我的應用程序時,徽章就像這樣:
但是當我打開使用圖標本身的應用程序,徽章沒有顯示出來:
任何人有任何知道我做錯了嗎?
請讓我知道,如果我能改善這個問題!
不知道這是否與你的問題有關,但他使用的功能是**棄用**。你不應該在iOS10中使用這個功能。如果它有效,那是因爲你很幸運。見[這裏](https://stackoverflow.com/questions/37956482/registering-for-push-notifications-in-xcode-8-swift-3-0)和[這裏](https://stackoverflow.com/問題/ 39883112 /如何到獲得最體對的一推通知發送的 - 從 - 火力控制檯功能於IOS-10)。 – Honey
在iOS10中,如果您想在用戶**輕按**時進行回調,則必須使用['didReceiveNotificationResponse'](https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649501-usernotificationcenter?language= objc) – Honey