【发布时间】:2017-12-21 07:36:17
【问题描述】:
下面的代码我曾经在后台模式下编写某些任务。但这仅在任务结束后执行 3 分钟。所以我想执行特定的任务直到它完成。
func registerBackgroundTask() {
backgroundTask = UIApplication.shared.beginBackgroundTask { [weak self] in
self?.endBackgroundTask()
}
assert(backgroundTask != UIBackgroundTaskInvalid)
}
func endBackgroundTask() {
print("Background task ended.")
AppConstants.sharedInstance.scheduleLocalNotification(message: "Background task ended.", title: "status!")
UIApplication.shared.endBackgroundTask(backgroundTask)
backgroundTask = UIBackgroundTaskInvalid
}
self.registerBackgroundTask()
self.perform(#selector(self.backgroundTimer(challengeId:)), with: "\(tag)", afterDelay:600)
【问题讨论】:
标签: ios swift uiapplication performselector