所有通知在打开其中一个后消失

我有一个服务器,发送给我推送通知,让我们说我有5个通知在我的手机上。 如果我打开其中一个,所有其他通知消失。 我只想要点击消失。

这是我如何处理接收通知:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { if ( application.applicationState == UIApplicationState.Inactive || application.applicationState == UIApplicationState.Background ) { // navigating user to a view controller } application.applicationIconBadgeNumber = 0 } 

通过将applicationIconBadgeNumber设置为0 ,您还可以从通知中心删除每个通知。

这也在这里讨论: iOS应用程序:如何清除通知?

此外,无法以编程方式删除单个通知,但是从iOS8开始,当用户点击单个通知时,操作系统将为您处理此问题。 这也在这里讨论: 从通知中心删除单个远程通知

如果你想快速清除通知

 import UserNotifications if #available(iOS 10.0, *) { let center = UNUserNotificationCenter.current() center.removeAllPendingNotificationRequests() // To remove all pending notifications which are not delivered yet but scheduled. center.removeAllDeliveredNotifications() // To remove all delivered notifications } else { UIApplication.shared.cancelAllLocalNotifications() }