可以使用推送通知来运行代码而不通知用户吗? [英] Can push notifications be used to run code without notifying user?
问题描述
我有一个应用程序需要每 24 小时与服务器通信一次(以刷新其数据).即使应用程序未打开或在后台运行,也需要执行此操作.
I have an app which needs to communicate with a server (to refresh it's data) once every 24 hours. This needs to happen even if the app is not open, nor in the background.
理想情况下,我想要的是:
Ideally what I'd like is:
- 我的服务器每 24 小时向 iPad 发送一次推送通知
- 这会唤醒应用,并运行刷新数据所需的代码
- 然后丢弃通知
这有可能吗?
应用程序是否仅在用户点击通知后唤醒?或者我可以在显示通知之前运行一些代码吗?我什至可以丢弃通知消息吗?
Is any of this possible?
Is the app only woken up AFTER the user clicks on the notification? Or can I run some code before showing the notification?
Can I even discard the notification message?
如果推送通知不是执行此操作的正确方法,那是什么???
If Push notifications are not the right way to do this, what is???
谢谢各位!
推荐答案
随着 iOS 7 的发布,这终于可以使用远程/静默通知.它们的工作方式与推送通知相同,但不是立即提醒用户,而是可以启动后台获取模式并上传/下载新内容.
With release of iOS 7 this is finally possible using Remote/Silent notifications. They work same as Push notifications but instead of alerting the user immediately they can fire up background fetch mode and upload/download new content.
这里是简单的教程:http://www.objc.io/issue-5/multitasking.html
这篇关于可以使用推送通知来运行代码而不通知用户吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!