IOS5:非运行状态下的图标徽章
我搜索了很多在应用程序未运行时处理图标徽章的解决方案。
我编写了一个接收推送通知的应用程序,但是在运行状态下,我可以在 application:didReceiveRemoteNotification:
函数中更新徽章,但我仍然不知道如何在应用程序运行时更新图标徽章没有运行。
我的应用程序的通知菜单下的“徽章应用程序图标”开关处于打开状态,但在接收远程通知时,图标徽章不会更新。
代码在设备上运行,不涉及模拟器。
我的通知包含一个徽章,
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => '1' // Wrong, see edit...
);
我正在使用一个简单的 php 脚本来生成它。
我错过了什么吗?
编辑:
我发现我将徽章属性作为字符串而不是数字发送。
php 中的正确代码是:
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => 1 // Right
);
使用数字徽章值,图标徽章已正确更新。
I searched a lot for a solution to handle icon badging while the application is not running.
I wrote an app that receives push notifications but, while in running state i can update the badge in the application:didReceiveRemoteNotification:
function, i still can't figure out how to update the icon badge while the application is not running.
The "Badge App Icon" switch is ON under the notifications menu of my app but when receiving remote notifications the icon badge is not updated.
The code is running on a device, no simulator involved.
My notification contains a badge
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => '1' // Wrong, see edit...
);
I'm using a simple php script to generate it.
Am i missing something?
Edit:
I found out that i was sending the badge properties as a string instead of a number.
The correct code in php is:
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => 1 // Right
);
With the numeric badge value the icon badge is correctly updated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当系统收到推送通知时,它会检查通知是否包含徽章号码。如果是这样,它会将您的应用程序徽章设置为该数字。
您是否在推送通知中设置徽章编号?
When the system receives a push notification it checks whether the notification contains a badge number. If it does it will set your apps badge to that number.
Are you setting the badge number in the push notification?