打开其中一个后所有通知消失 [英] All notifications disappearing after opening one of them
问题描述
我有一个服务器向我发送推送通知,假设我的手机上有 5 个通知.如果我打开其中一个,所有其他通知都会消失.我只想点击一个消失.
这是我处理接收通知的方式:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {if ( application.applicationState == UIApplicationState.Inactive || application.applicationState == UIApplicationState.Background ){//将用户导航到视图控制器}application.applicationIconBadgeNumber = 0}
通过将 applicationIconBadgeNumber
设置为 0
,您还可以从通知中心移除所有通知.>
这里也讨论过这个:iOS 应用:如何清除通知?
此外,无法以编程方式删除单个通知,但从 iOS8 开始,当用户点击单个通知时,操作系统将为您处理此问题.这也在这里讨论过:从通知中心移除单个远程通知
I have a server that sends me push notifications and let's say that I have 5 notifications on my phone. If I open one of them all other notifications disappears. I want only the one clicked to disappear.
This is how I handle receiving notifications:
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
}
By setting the applicationIconBadgeNumber
to 0
, you also remove every notification from the notification center.
This has also been discussed here: iOS application: how to clear notifications?
Furthermore, it is not possible to programmatically remove a single notification, but from iOS8 on, the OS will handle this for you when a user taps a single notification. This has also been discussed here: Remove single remote notification from Notification Center
这篇关于打开其中一个后所有通知消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!