开发者

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 e.g. Skype run in the background. I would like to have my app run in the bac开发者_Python百科kground also, waking up every 1 seconds to update some data and then going to sleep again. How can I do this? I gather that NSTimer's do not work in the background.


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. 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.


See Executing Code in the Background


You would need to use push notifications to push information to the app (like the Facebook or Skype app). See this documentation from Apple on how to use push notifications.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜