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

时间:2022-08-26 21:31:44

I am working with push notifications. When I get a notification it comes with 2 button, view and close. 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

我正在使用推送通知。当我收到通知时,它会附带2个按钮,查看并关闭。如果我点击视图,它会打开应用程序,当我点击关闭按钮时,它只会在应用程序图标上显示徽章编号。然后,当我再次打开我的应用程序时,徽章编号应该消失,但事实并非如此。如果用户点击应用图标,如何删除该徽章编号?感谢名单

2 个解决方案

#1


39  

put the following code somewhere in your applicationDidFinishLaunching or applicationDidBecomeActive.

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

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

#2


1  

What you could do is omit the badge key from your remote notification so that any badge number currently shown is removed. 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.

但我不确定你为什么要这样做。

#1


39  

put the following code somewhere in your applicationDidFinishLaunching or applicationDidBecomeActive.

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

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

#2


1  

What you could do is omit the badge key from your remote notification so that any badge number currently shown is removed. 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.

但我不确定你为什么要这样做。