下面的代码我已经习惯在后台模式下写一些任务。但是这个任务在结束任务后只执行了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)