当在后台应用程序时,时间徽章计数未设置最后 5 天前正常工作。
徽章计数每次由 php 后端 ex 增加。当前徽章 = 10 然后在第二次推送后获得徽章 = 11

我正在使用波纹管有效载荷格式。如果波纹管格式有任何变化,请帮助我阅读也引用 Apple Push Notification Service.

推送通知负载是一个 JSON 负载:

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    }
}

注册用户通知设置
if (ios8)
    {
        if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
            UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
        }
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }

最佳答案

根据 Apple documentation 中对payload keys 的描述,与key 徽章关联的值必须是一个数字,所以你不能从payload 中递增badge 值(否则你无法区分递增或badge 设置为1) .

您可以在服务器端保存徽章值并在服务器上递增,因此它看起来像用户的递增。

10-08 10:57
查看更多