swift/ios refreshing app data when in background

本小妞迷上赌 提交于 2019-11-30 05:14:30

Use iOS Background Fetch feature where you can specify minimum background fetch interval. But actual interval between successive invocation of your code will be determined by iOS framework. For details checkout this link: http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520

I use this approach in my app and I think it is a preferred way of doing.

  1. You can use a local notification that can be presented from the background in case your condition is met.

  2. Correct, iOS will eventually shut down the background process, you can't enforce continuous background activity. Use the backgroundTimeRemaining property to check how much time your application has left and try to handle it as gracefully as possible by calling endBackgroundTask so that iOS does not force kill your app.

As a solution, you could think about using remote notifications with with content-available : YES, which runs the didReceiveRemoteNotification

Have a look at the Parse.com Their local datastore is an abstraction for what you are trying to acheive. By the way, is it really necessary to refresh in the background. If call is relatively quick, there is no need to refresh until the user open's the app. Background processes like that, using the net can be quite battery consuming when the user are not on a Wifi. So consider the use case carefully!

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