Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing a notification from notification center on click

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.

like image 375
Andy Davies Avatar asked Jan 26 '12 11:01

Andy Davies


People also ask

How do I see notifications I already clicked on?

Pull down your Notification Shade once and then scroll down to the bottom of your notifications. You should now see a History button (Figure 3). The History button has been added to your Notification Shade. Tap History to access your past 24 hours of notifications (Figure 4).

How do I turn off notifications on Notification Center?

Touch and hold the notification, and then tap Settings . Choose your settings: To turn off all notifications, turn off All notifications. Turn on or off notifications you want to receive.

How do I get rid of the icons on my Notification Center screen?

In Settings, locate “Face ID & Passcode” (for devices with Face ID) or “Touch ID & Passcode” (for devices with a home button) and tap it. Next, enter your passcode. In Passcode settings, locate the “Allow Access When Locked” section. Tap the switch beside “Notification Center” until it is turned off.

How do I get rid of unwanted notifications on my iPhone?

To turn off notifications selectively for apps, go to Settings > Notifications > Siri Suggestions, then turn off any app.


1 Answers

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.

like image 98
Andy Davies Avatar answered Sep 28 '22 04:09

Andy Davies