iPhone:当应用程序关闭/在后台时如何设置应用程序徽章?
当应用程序处于后台模式甚至关闭时,是否可以设置应用程序徽章?我还没有找到任何东西。
is it possible to set the application badge, while the app is in background mode or even closed? I haven't found anything, yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您的应用程序中,您可以使用
UIApplication
的applicationIconBadgeNumber
属性来设置徽章编号:如果您想在用户不启动应用程序的情况下更改徽章,则需要使用推送通知服务。 推送通知服务编程指南应该包含您所需要的所有信息需要。
From within your application you can use the
applicationIconBadgeNumber
property ofUIApplication
to set the badge number:If you want to change the badge without the user launching your app, you need to use the push notification service. The Push Notification Service Programming Guide should have all the info you need.
可以通过推送通知(如您标记的那样)但请记住,如果用户不允许推送通知,它将无法工作。
要通过推送更新徽章编号,您需要在有效负载中包含以下内容:
有关有效负载的更多信息,请参阅 此苹果文档。
It is possible via push notifications (as you've tagged) but bare in mind that if the user has disallowed push notifications it won't work.
To update the badge number via push, you need to include the following in your payload:
For more info about the payload, see this apple doc.
我的应用程序徽章编号遇到了困难,该编号被设置为接受的答案状态。
我发现使用这个经过巧妙更改的代码效果更好:
如果您的徽章号码有问题,可能值得检查一下
I was having difficulties with my app badge number which was being set as the accepted answer states.
I found using this subtly changed code worked better:
Might be worth a check if you are having issues with your badge number
如果您不想使用推送通知,您可以安排本地通知来执行此操作。如果您强制退出应用程序,这将不起作用。
If you don't want to use push notification you can schedule a local notification to do this. This won't work if you force quit the application though.