单击时从通知中心删除通知 [英] 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.
Facebook 应用似乎肯定会在点击后删除推送通知.
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
和
- (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.
这篇关于单击时从通知中心删除通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文