ios – 在Swift更新徽章柜台

ios – 在Swift更新徽章柜台,第1张

概述使用以下代码,我可以在应用编译后立即在徽章图标中找到(2): func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { let installation = PFInstallation.currentInstall 使用以下代码,我可以在应用编译后立即在徽章图标中找到(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 – 在Swift更新徽章柜台全部内容,希望文章能够帮你解决ios – 在Swift更新徽章柜台所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1095849.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存