我的徽章增量有问题。我正在使用 CloudKit 推送通知,当我的应用收到推送通知时,它会从最后一个通知编号开始递增。
所以即使我使用以下方法将其重置为零:
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
...在 AppDelegate.swift 方法中,它将从一个更大的数字开始,例如 15,而不是 1。
我应该提到我的应用可以接收推送通知。当触发上述代码时,徽章消失(好像徽章计数器重置为 0),但这是暂时的。
这让我抓狂。有人可以帮我吗?
最佳答案
您的徽章计数在推送通知的有效负载内发送。
[aps: {
alert = {
body = "some body text for notification banner";
title = "title of the banner";
};
badge = 1; // the count that will be set to the badge
sound = default;
}, userInfo: {
// some key/value pairs for further processing. // e.g. deep linking.
}]
您应该在 public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
上设置断点并打印 userInfo 字典的内容。检查徽章计数。
关于swift - 每当我的应用程序收到推送通知时,它都会从最后一个徽章编号(不是 0)开始递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31852398/