在午夜更新应用程序徽章,并提供以下选项:应用程序未启动或在后台,徽章数量可能会减少
我正在阅读许多有关本地通知的内容以及它们如何帮助更新应用程序徽章编号。
我想在午夜更新此徽章,并将其值设置为我在午夜之前无法知道的数字。因此,如果可能的话,我想在午夜启动一个功能来更新/加载一些数据,检查要显示的数字,并将其显示在徽章上。
当然,要显示的数字与显示的数字无关,并且可以更低或更大。
预计这会起作用: - 当应用程序在后台时 - 当应用程序位于前台时 - 当应用程序未启动时,
您是否知道如何执行此操作,即使是部分操作?如果不可能,假设我可以在午夜之前知道徽章号码......这会帮助您找到有效的答案吗?这不是想要的,但如果我没有选择来完成这项工作,我将计划编写大量无用的代码来执行此操作......
I'm reading many things about Local Notifications and the way they can help to update the app badge number.
I'd like to update this badge at midnight, and set its value to a number I can't know before midnight. So I'd like, if possible, to launch a function at midnight that would update/load some datas, check the number to display, and display it on the badge.
Of course, the number to display is not relative to the displayed number, and can be lower or greater.
This is expected to work :
- When app is in background
- When app is in foreground
- When app is not launched
would you know a way to do this, even partially ? If not possible, let say I can make things to know the badge number before midnight... Would this help you for a working answer ? This is not wanted, but if I don't have the choice to make this work, I'll plan to write tons of useless code to do this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非您的应用程序适合“官方”多任务处理情况之一(VOIP、位置和背景音频),否则您能够在应用程序未运行时动态设置徽章编号的唯一方法是使用推送通知...应用程序无法运行代码来响应本地通知(至少在用户按下通知弹出窗口中的“查看”按钮之前)。
请参阅此文档了解您想要了解的所有内容可能想了解 iOS 中的本地和推送通知。
Unless your application fits into one of the "official" multitasking cases (VOIP, location, and background audio), the only way you're going to be able to dynamically set the badge number when your application isn't running is with push notifications... applications can't run code in response to a local notification (until the user presses the "View" button in the notification popup, at least).
See this document for everything you could ever want to know about local and push notifications in iOS.
您无法可靠地确保本地应用程序在需要时运行,除非您将其注册为 VoIP 应用程序或需要连续位置监控;在实际上不用于 VoIP 或导航的应用程序中,其中任何一个几乎肯定会导致应用程序商店拒绝。
最好的办法是将徽章作为推送通知发送。假设您控制的服务器可以知道徽章编号应该是什么,它可以向您的应用程序发送仅包含该徽章值的通知(不一定是警报弹出窗口或声音)。 Urban Airship 是一种发送推送通知的好方法,无需进行大量配置和设置。
You can't reliably ensure that your local app will run when it needs to unless you register it as a VoIP app or as requiring continuous location monitoring; either of these, in an app that's not in fact used for VoIP or navigation, will almost certainly result in an App Store rejection.
Your best bet is to send the badge as a push notification. Assuming that a server you control can know what the badge number is supposed to be, it can send a notification with just that badge value—not necessarily an alert popup or sound—to your app. Urban Airship is a good, simple way to send push notifications without having to do a lot of configuration and setup.
你很可能能够做到这一点。请参阅 Apple 指南来运行后台代码。
You very well may be able to do this. Look at the Apple Guide to running code in the background.