您可以试用 App42 后端服务,该服务提供在服务器端维护的推送徽章计数的自动递增。更多详情可以关注blog的链接。以下是博文内容:
以下是少数几个可以通过 App42 推送通知中的自动增量徽章计数来实现的用例。
推送徽章自动加1,需要发送推送消息,如下图。
PushNotificationService pushNotificationService = App42API.BuildPushNotificationService (); // Initializing PushNotification Service.
string userName = "UserName";
string message= "{'badge':'increment'}";
pushNotificationService.SendPushMessageToUser(userName,message, new UnityCallBack())
注意:解释的示例适用于 Unity/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 - 此方法用于更新用户购买的所有设备的推送徽章计数。在这种情况下,我们假设用户在他的名下注册了多个设备。