Micgal
Micgal

Reputation: 133

Download and refresh data in background when app is running

I am looking a way, which should I follow to implement background download data. I mean if app is running (not in background mode) how to download data in a loop every 30 seconds? For standard download when viewWillAppear I am using Alamofire. Could someone show me the path to follow? What should I look for?

Upvotes: 0

Views: 167

Answers (2)

Micgal
Micgal

Reputation: 133

The solution is so simple, based on one of comment I've just put the timer

self.timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.downloadData), userInfo: nil, repeats: true)

Upvotes: 1

rajtharan-g
rajtharan-g

Reputation: 452

You can use the fetch logic in viewWillAppear. But if you want the data to be refreshed frequently, you can use timers to fetch the data. For fetching the data in background, you should enable background fetching under capabilities. You can init timers in a shared instance and then use that.

Upvotes: 0

Related Questions