【发布时间】:2017-12-21 09:54:42
【问题描述】:
我有一个使用 PHP EasyAPNS 通知的推送通知应用程序在 Swift 3、iOS 10 上运行良好。但我无法理解的一件事是,为什么当我从通知警报启动应用程序时 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中,如果你想在用户点击时有回调,那么你必须使用
didReceiveNotificationResponse
标签: ios swift3 push-notification apple-push-notifications ios10