Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

ios - 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
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...