当点击推送通知时,推送通知提醒会隐藏在通知横幅中,但是当我只是通过点击通知打开应用时,推送通知自动清除,为什么?启动我的应用时,我没有重置徽章。 让我们说我的手机上有5个通知。如果我打开其中一个,其他所有通知都会消失。我只希望点击的一个消失。是的,我知道这是ios的默认属性,但我想显示通知,直到用户手动点击或清除它。我这样处理了
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("this calls")
print(userInfo)//json
let aps = userInfo["aps"] as! [String: AnyObject]
let new = userInfo["news"] as! [String: AnyObject]
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("navVC") as? navViewController
let state:UIApplicationState = application.applicationState
if (state == UIApplicationState.Inactive || state == UIApplicationState.Background) {
if let _ = aps["alert"] as? String,let newsId = new["news_id"] as? Int {
print(newsId)
NSUserDefaults.standardUserDefaults().setInteger(newsId, forKey: "K_Push_Id")
NSUserDefaults.standardUserDefaults().synchronize()
}
if let category_name = new["category_name"]{
print(category_name)
NSUserDefaults.standardUserDefaults().setObject(category_name, forKey: "category_name")
NSUserDefaults.standardUserDefaults().synchronize()
}
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
NSNotificationCenter.defaultCenter().postNotificationName("pushNotificationIdentifier", object: nil)
}
}
答案 0 :(得分:0)
我在appdelegate中做过这样的事情
func applicationDidBecomeActive(application: UIApplication) {
application.applicationIconBadgeNumber = 0;
}
因此,每次如果我打开应用程序,则将applicationIconBadgeNumber
设为零,如果applicationIconBadgeNumber
为零,则清除通知中心的所有通知。