ios – 在Swift更新徽章柜台

使用以下代码,我可以在应用编译后立即在徽章图标中找到(2):
func application(application: UIApplication,didRegisterForRemoteNotificationsWithDevicetoken devicetoken: NSData) {
    let installation = PFInstallation.currentInstallation()
    installation.setDevicetokenFromData(devicetoken)
    installation.badge = 2
    installation.saveInBackground()
}

我尝试了下一个变体:初始化一个新的var badgeCount = 0及更高版本:

func application(application: UIApplication,didRegisterForRemoteNotificationsWithDevicetoken devicetoken: NSData) {
    badgeCount++
    let installation = PFInstallation.currentInstallation()
    installation.setDevicetokenFromData(devicetoken)
    installation.badge = badgeCount
    installation.saveInBackground()
}

但是当我收到新的通知,它不会更新到1.有谁知道如何解决它?

解决方法

它不会使用此方法更新徽章编号,除非应用程序实际打开.如果要在收到通知后更新徽章编号,则需要将json push通知的徽章属性设置为所需的号码.

如果您发送正常消息(不使用儿子),则会有一个切换来增加徽章编号,只需勾选该标记.如果你使用Json然后使用这个:

{
    "aps": {
        "alert": "Test Push Notification","sound": "yourSound.aiff","Badge": "desirednumber"
    }
}

请注意,如果您不希望从服务器发送,您也可以使用Parse的客户端推送将其从一个设备发送到另一个设备,进入Parse.com中的应用程序中的设置并启用“客户端推送”,您可以然后将上述Json发送到另一个用户的设备.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...