【发布时间】:2016-06-14 04:15:27
【问题描述】:
当点击推送通知时,推送通知警报会从通知横幅中隐藏起来,但当我只是打开应用程序而不是点击通知时,推送通知会自动清除,为什么?启动我的应用程序时,我没有重置徽章。 假设我的手机上有 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)
}
}
【问题讨论】:
-
这不仅仅是您的应用程序。一旦你打开它,任何应用程序都会确保通知消失。或者点击该应用的一个特定通知,因为该应用会在您IN该应用时负责任地向您显示所有通知。不过有道理。
-
但我想在通知中心显示通知,直到用户手动打开它或清除它
-
用户必须在通知中心启用它们,在其他地方它们不会显示,即使你想要;)
-
我说的是用户在通知中心案例中启用了它们
标签: ios swift push-notification