简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM