简体   繁体   English

如果单击推送通知中的关闭按钮,如何删除徽章编号?

[英]How can I remove the badge number if I click on close button in push notification?

I am working with push notifications. 我正在使用推送通知。 When I get a notification it comes with 2 button, view and close. 当我收到通知时,它带有2个按钮,可查看并关闭。 If I click on view it opens the app and when I click the close button it does nothing but a badge number appears on the app icon. 如果我单击视图,它将打开应用程序,当我单击关闭按钮时,它只会执行任何操作,但会在应用程序图标上显示徽章编号。 Then when I open my app again that badge number should disappear but it doesn't. 然后,当我再次打开我的应用程序时,该徽章编号应该会消失,但不会消失。 How can I remove that badge number if user clicks on app icon? 如果用户单击应用程序图标,如何删除该徽章编号? Thanx 谢谢

将以下代码放在applicationDidFinishLaunching或applicationDidBecomeActive中。

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

What you could do is omit the badge key from your remote notification so that any badge number currently shown is removed . 您可以做的是从远程通知中省略badge密钥,以便删除当前显示的任何徽章编号 If you want a badge to show up if the user taps View, you can set a badge number using [UIApplication sharedApplication].applicationIconBadgeNumber . 如果希望在用户点击查看时显示徽章,则可以使用[UIApplication sharedApplication].applicationIconBadgeNumber设置徽章编号。

But I'm not sure why you'd want to do this. 但是我不确定为什么要这么做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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