简体   繁体   中英

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?

解决方案非常简单,基于我刚刚设置的评论之一

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM