iosswiftios9background-fetch

How to fetch data in background every hour in Swift even the app is terminated?


I am making an app that provides functionality to fetch data every hour. It fetches data even when the app terminates. How can I implement this functionality?

After a lot searching I found background fetching using performFetchWithCompletionHandler. Will this function work even if my app terminates? What I mean is if my app is in closed or terminated state, can I call this function automatically?


Solution

  • You can't do anything if your app is in terminated state. Apple is not allowing anything (except receiving notification) in terminated or closed state.

    You are also restricted for background execution also. You can perform specific kind of task in background mode like : Location update,Music playing, VOIP, finite length task, Newsstand downloads, etc. You can refer apple documentation for more details about background execution.

    Hope this will help :)