在我的应用程序中,我需要一个始终与应用程序并行运行的thread
(换句话说,它总是在后台运行)。将在此线程上运行的进程将执行以下操作:
1) check for a specific value in my sqlite database
2) if the value is what i need, it will make a network call and get some data from a web service
3) parse the received data and save it in sqlite database
4)sleep for a few minutes
5) repeat the process again
我怎样才能做到这一点?我是否使用NSOperationsQueue?
答案 0 :(得分:0)
您可以按如下方式使用dispatch_async
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) {
do {
if "value is what you need" {
"make the network call and process the data"
}
NSThread.sleepForTimeInterval(100)
} while true