Apple 推送通知不会自动更改图标徽章 [英] Apple push notification not changing icon badge automatically

查看:23
本文介绍了Apple 推送通知不会自动更改图标徽章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到我的 iPhone(4S,iOS 5.1)中的邮件应用程序在新邮件到达时自动更新徽章计数,即使应用程序没有运行也是如此.所以也可以在我的应用中实现这种行为,对吗?

I have seen the mail app in my iPhone (4S, iOS 5.1) automatically updates the badge count if new mail arrives, even when app is not running. So it is possible to achieve this behavior in my app also, right?

我的应用程序成功注册了所有 3 种类型的推送通知 - 徽章、警报和声音.此应用程序的所有 3 种远程通知类型的电话设置"均设为开启".

My application successfully registers for push notifications for all 3 types - Badge, Alert and Sound. Phone Settings is set ON for all 3 types of remote notifications for this application.

我的应用接收远程通知并显示警报、播放声音,但它不会更新徽章编号.如果我通过警报上的查看"按钮启动应用程序,那么我的应用程序可以完美地读取徽章值,并且我可以从代码中更改/删除/设置图标徽章.

My app receives remote notifications and shows alert, plays sound, but it does not update the badge number. If I launch the app via the View button on the alert, then my app can read the badge value perfectly and I can change/remove/set the icon badge from code.

iOS 无法在通知到达时自动更改我的应用程序图标徽章的任何具体原因?我看过所有类似的帖子,他们都在讨论手机设置,或者它注册的通知类型,或者检查有效负载 JSON 是否包含徽章.

Any specific reason why iOS cannot change the icon badge of my app automatically when the notification arrives? I have seen all the similar posts, they are all discussing about either phone settings, or about notification types that it registered, or about checking the payload JSON includes badge or not.

是否还有其他原因可能导致此问题?

Is there any other reason that might cause this problem?

这是我的代码块:

每次启动应用程序时注册 APNs -

Register for APNs every time app is launched -

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];

几乎立即收到设备令牌.令牌已发送给提供商,我正在接收通知.警报和声音有效.但是在我启动应用程序并手动更改它之前,徽章不会自动生效.请帮忙.

Device token received almost instantly. Token has been sent to provider, and I am receiving notifications. Alerts and Sounds works. But badge has no automatic effect until I launch the app and change it manually. Please help.

推荐答案

该问题现已修复.提供者服务器正在发送带引号的徽章编号(作为 JSON 字符串,即9").奇怪的是,APNs/iOS 不能将其识别为整数.现在引号被删除,它的工作原理:)

The issue is now fixed. The provider server was sending the badge number in quotation marks (as JSON String, i.e. "9"). Strange that APNs/iOS does not recognize it as integer. Now the quotes are removed and it works :)

这篇关于Apple 推送通知不会自动更改图标徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆