[英]If NSTimer does not work when an iOS app is in the background, how can I get my app to wake up periodically?
I have noticed that some apps eg Skype run in the background.我注意到某些应用程序(例如 Skype)在后台运行。 I would like to have my app run in the background also, waking up every 1 seconds to update some data and then going to sleep again.
我也想让我的应用程序在后台运行,每 1 秒唤醒一次以更新一些数据,然后再次进入睡眠状态。 How can I do this?
我怎样才能做到这一点? I gather that NSTimer's do not work in the background.
我收集到 NSTimer 不能在后台工作。
You can't.你不能。 Voice-over-IP apps get a special exception for this, basically the system manages a network socket for them and wakes them up if there's data.
IP 语音应用程序对此有一个特殊的例外,基本上系统会为它们管理一个网络套接字,并在有数据时唤醒它们。 There's no way to do the same with a timer.
没有办法用计时器做同样的事情。
By the way, waking your app every second, your battery wouldn't last half a day.顺便说一句,每秒唤醒你的应用程序,你的电池不会持续半天。
You would need to use push notifications to push information to the app (like the Facebook or Skype app).您需要使用推送通知将信息推送到应用程序(如 Facebook 或 Skype 应用程序)。 See this documentation from Apple on how to use push notifications.
请参阅 Apple 提供的有关如何使用推送通知的文档。
Not every second though, that would drain the battery.不是每一秒,这会耗尽电池。 Other than that, there isn't really a way unless you are running a VoIP app.
除此之外,除非您正在运行 VoIP 应用程序,否则没有真正的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.