简体   繁体   English

推送通知更改AppIcon的徽章

[英]Push Notification Changing Badge of AppIcon

I am working on an app that can receive Push-Notifications . 我正在开发一个可以接收Push-Notifications的应用程序。 When a notification is received, I need to change the number of the icon's badge and increment it. 收到通知后,我需要更改图标徽章的编号并增加它。 Those notifications are stored in a UITableView in my app. 这些通知存储在我的应用程序中的UITableView中。 When a row is pressed, this means that the notification has been read so I want to decrement the badge. 当按下一行时,这意味着已经读取了通知,所以我想减少徽章。 I am new to push notifications and badges and I really couldn't find any efficient way to do it 我是新手推送通知和徽章,我真的找不到任何有效的方法来做到这一点

any solutions ? 任何解决方案

Thank you. 谢谢。

You can't automatically increment a badge from a notification. 您无法从通知中自动增加徽章。 Your notification payload must contain the badge property that will be set to the exact value you want for your badge. 您的通知有效内容必须包含badge属性,该属性将设置为badge所需的确切值
To set the badge value from within your app, you can use: 要在应用内设置徽章值,您可以使用:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:someInteger];

If you want to increment the badge by one every time you receive a notification, you need to keep track of your user's badge server-side. 如果您希望每次收到通知时将徽章增加1,则需要跟踪用户徽章服务器端。
For example, if you send 3 notifications to an user, you will have a badge column in your database for this user with 3 as a value. 例如,如果向用户发送3个通知,则数据库中将为此用户提供一个badge列,其中3为值。 If the user opens his app and taps one of the notifications, your app will have to set the badge icon to 2 and send a request to your server to decrease the database value to 2. 如果用户打开其应用并点按其中一个通知,则您的应用必须将徽章图标设置为2并向服务器发送请求以将数据库值降低为2。

TL;DR: There is no such thing as a badge:+1 or badge:autoincrement in a notification's payload. TL; DR:没有badge:+1badge:autoincrement通知的有效载荷中的badge:autoincrement You have to keep track of the badge's value server-side. 您必须跟踪徽章的值服务器端。

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

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