即使应用程序没有运行,如何在每天下午13:00之后运行一个功能
答案 0 :(得分:0)
如果您希望在应用程序处于后台运行而未关闭的情况下运行该功能,则应使用后台任务。如:
var timer = NSTimer(timeInterval: Your nstimerinterval, target: self, selector: "someBackgroundTask:", userInfo: nil, repeats: true)
func someBackgroundTask(timer:NSTimer){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), { () -> Void in
println("You can do background tasks here.")
dispatch_async(dispatch_get_main_queue(), { () -> Void in
println("If you want to update your UI, you should do it here.")
})
})
}