iPhone : Running services in the background

故事扮演 提交于 2020-01-01 07:21:32

问题


Having a look around, am I correct in thinking that the only type of background services are audio, voip and location services and so that if I wanted to communicate with a server I have to use push notifications. This means that badges are only uses for push notifications.

Update: I want to check for updates on the server every 5 minutes or so. So the device is checking the server, not the server pushing to the device. I suppose email is an example. It polls the server.

Thanks Simon


回答1:


You have a number of options:

  • Push Notifications
    This is the most friendly for battery and device resources; requires a server-side implementation of the notification system, though. --- Possibly not what you are currently looking for, but definitely the "best" solution when it comes to instant notifications and network-loss handling.

  • Running the App in the background
    Apps can run in the background and keep checking a server for new data, etc... However, it is not guranteed that the application may run for a long time since iOS's process manager might put your App to sleep or quit it unexpectedly. --- Possibly comes closer to what you are looking for and might work for basic tests; but is not very reliable.

  • Supporting Multitasking
    This is obviously the "best" way to do it. Implement support for multitasking and have iOS wake up your application whenever traffic is detected. This can be done using the "voip" background-mode.




回答2:


Push Notifications sounds like your best bet. Rather than have the client check for updates every 5 minutes have the server tell your client when there is an update that it should be aware of.

Whether this is going to annoy your users or not depends on how frequently you're pushing updates. Notifications on iOS are fairly intrusive so use them sparingly.



来源:https://stackoverflow.com/questions/5252575/iphone-running-services-in-the-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!