Remove single remote notification from Notification Center
Asked Answered
A

3

25

my app receives remote notification from Apple server.

Is there a way to remove a single remote notification from notification center (the drop-down menu available from iOs 5.0+), when the user taps on it?

enter image description here

Thanks!

Appurtenant answered 29/3, 2012 at 12:59 Comment(9)
Push Notifications (what you get from Apple's servers) and NSNotificationCenter are two different things...can you explain a little more clearly what it is you're trying to do?Differentia
Thanks for your reply. I was referring to drop-down menu with notifications inside (available from iOS 5.0+)Appurtenant
You still didn't really answer my question. First of all, local notifications and push notifications show up in N.C. Secondly, what do you mean by remove a single notification? You want to remove it without the user tapping the X? Or when they tap the X, you want only one notification to be removed as opposed to all for your app?Differentia
hi, sorry for my late response. I'm using push notification. I want to remove the push notification (from drop-down menu) that the user taps; only this push notification. ThanksAppurtenant
Does anybody know if there have been any changes in this area for iOS6?Vomer
hi @Appurtenant .. were u able to get a solution for it..we are also trying to remove a particular notification from the notification center when an user taps on that notification. Thanks in advance.Susurrate
hi! Any solutions on this??Asquith
How to remove all notifications without the user click and didn't launch app?Standoff
hey @Appurtenant have you got the solution .Moen
G
27

There is no way to remove a specific notification as of iOS SDK 5.0. The way to remove all the notifications from your app so they don't show in the Notification Center when the user opens the app from one of them, is to set the app badge to 0, like this:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

EDIT: on iOS 8, SpringBoard seems to be automatically dismissing a notification when you tap on it on the Notification Center to open the app.

Gallium answered 13/5, 2012 at 6:46 Comment(5)
I can't get this to work. I have read it in another answer too. has it changed?Khudari
I had to add [[UIApplication sharedApplication] cancelAllLocalNotifications]; to get it to work.Khudari
But what if it's not local notifications...?Gallium
Have try with same. But notification is still there in notification center.Phyto
This will only works if the badge was greater than 0. Otherwise, you must increment manually like so https://mcmap.net/q/394115/-remove-push-from-notificationcenter-after-app-has-been-openedSarraute
G
9

Here is a suggestion, though it does have its flaws, and I haven't tried it myself:

  • Push a silent notification (contentAvailable:true), don't include a "alert" inside the push, place the alert text in a custom property of the push
  • Handle the incoming push and trigger a local notification, display it immediately
  • If the user clicks the local notification, use the [UIApplication cancelLocalNotification:] which should remove the notification from the notification center.
Gibbeon answered 26/1, 2015 at 15:4 Comment(2)
You won't be able to create a local notification in case the app is killed.Ananthous
Also note that a silent notification (i.e. no alert inside the push) means you are forced into low priority mode. If you need timely delivery, this solution doesn't work.Aldana
C
2

When you call the method: [application cancelAllLocalNotifications]; inside the AppDelegate methods:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

and

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

All Local and Push Notifications will be remove on that for the particular app.

Crackerjack answered 10/5, 2013 at 7:31 Comment(3)
What if you don't want to cancel the scheduled local notiifcations...? That method has a different side effect, it's not a solution to the proposed problem.Gallium
please dont use this method, especially if you have scheduled local notification for some other different purposeJo
I just tried this on iOS 10, and AFAICT it did not remove the remote notification, just the local notifications (which makes sense given the name of the function, heh)Aldana

© 2022 - 2024 — McMap. All rights reserved.