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!

MaTTP
  • 953
  • 2
  • 12
  • 27
  • 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? – jmstone617 Mar 29 '12 at 14:20
  • 1
    Thanks for your reply. I was referring to drop-down menu with notifications inside (available from iOS 5.0+) – MaTTP Mar 29 '12 at 14:46
  • 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? – jmstone617 Mar 30 '12 at 20:24
  • 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. Thanks – MaTTP May 04 '12 at 10:03
  • 2
    Does anybody know if there have been any changes in this area for iOS6? – Gruntcakes Oct 01 '12 at 21:12
  • hi @MaTTP .. 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. – sm abbas Mar 06 '13 at 20:46
  • hi! Any solutions on this?? – Frade Oct 29 '13 at 11:14
  • How to remove all notifications without the user click and didn't launch app? – Hari Babu Jan 30 '15 at 09:32
  • hey @MaTTP have you got the solution . – Garry Oct 16 '15 at 08:18

3 Answers3

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.

Fry
  • 6,235
  • 8
  • 54
  • 93
Javier Soto
  • 4,840
  • 4
  • 26
  • 46
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.
Vamos
  • 2,701
  • 2
  • 24
  • 37
  • 2
    You won't be able to create a local notification in case the app is killed. – Puneet Jul 24 '16 at 18:50
  • 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. – user435779 Mar 16 '17 at 16:15
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.

Community
  • 1
  • 1
MyXEDNotes
  • 209
  • 1
  • 4
  • 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. – Javier Soto Jul 11 '13 at 23:56
  • 1
    please dont use this method, especially if you have scheduled local notification for some other different purpose – Hashim MH Aug 28 '15 at 06:41
  • 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) – user435779 Mar 16 '17 at 16:51