Almis Almis - 4 months ago 18
iOS Question

All notifications disappearing after opening one of them

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