ios 单击时从通知中心删除通知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9017348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Removing a notification from notification center on click
提问by Andy Davies
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.
一旦点击,Facebook 应用程序似乎肯定会删除推送通知。
回答by Andy Davies
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.
您将保留徽章计数,并在通知中心点击时清除推送通知。