Removing a notification from notification center on click
Asked Answered
N

1

15

Is it possible to remove the push notification from the notification center when one is clicked and the app launches?

Most apps seem to leave the notification in place. I read on another question that this:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; 

may work however it doesn't work for me.

The Facebook app definitely seems to remove the push notifications once clicked on.

Novick answered 26/1, 2012 at 11:16 Comment(2)
Is there any particularity for ipad?Dentelle
hi! Any solutions on this?? Thanks!Micturition
N
23
int badgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeCount];

If you add this to both

- (void)applicationWillEnterForeground:(UIApplication *)application

And

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

You will retain the badge count, and clear the push notification when it is clicked in the notification center.

Novick answered 27/1, 2012 at 16:33 Comment(4)
What if I want to remove only the notification the user clicked on, and not all notifications in the notification center?Pink
According to this: #9926354 You cannot.Undershrub
@AlaaNassef Of course you can, [[UIApplication sharedApplication] cancelLocalNotification:yournotification];Fernanda
Its not working for me. Notification is not cleared when I click on it.Amenra

© 2022 - 2024 — McMap. All rights reserved.