您可以尝试App42后端服务,它提供服务器端维护的推送徽章计数的自动增量。欲了解更多详情,你可以点击链接blog。以下是博文的内容:
以下是可通过App42推送通知中的自动增量徽章计数实现的少数用例。
对于推送徽章自动增加1,您需要发送推送消息,如下所示。
PushNotificationService pushNotificationService = App42API.BuildPushNotificationService(); // Initializing PushNotification Service.
string userName = "UserName";
string message= "{'badge':'increment'}";
pushNotificationService.SendPushMessageToUser(userName,message, new UnityCallBack())
N.B:样品解释为统一/ C#,但相同的处理可以对他人也被应用。
如果要为徽章规定任何编号或想要将徽章数减少到零,则可以使用此方法在用户点击通知时更新计数。在这种情况下,您必须调用updatePushBadgeforDevice或updatePushBadgeforUser。
PushNotificationService pushNotificationService = App42API.BuildPushNotificationService(); // Initializing PushNotification Service.
string userName = "UserName";
string deviceToken = "DeviceToken";
int badges = 10; // For clear count make it 0
pushNotificationService.UpdatePushBadgeforDevice(userName, deviceToken, badges, new UnityCallBack());
PushNotificationService pushNotificationService = App42API.BuildPushNotificationService(); // Initializing PushNotification Service.
string userName = "UserName";
int badges = 10; // For clear count make it 0
pushNotificationService.UpdatePushBadgeforUser(userName, badges, new UnityCallBack());
updatePushBadgeforDevice
- 此方法用于更新用户注册的特定设备的推送标志计数。
updatePushBadgeforUser
- 此方法用于更新用户采购的所有设备的推送标志计数。在这种情况下,我们假设用户有多个设备以他的名字注册。
自动增量仍然不可能吗?我正在构建一个名为[AcaniChat]的聊天应用程序(https://github.com/acani/AcaniChat)。与iPhone本机Messages应用程序一样,徽章计数等于新(未读)消息的数量,并且您会收到每条新消息的推送通知。所以,如果可以自动增加,我不必在服务器上存储每个设备令牌的徽章数量。 – ma11hew28 2012-09-16 00:17:53