0
以下のコードよりバックグラウンドモードで特定のタスクを書きましたが、これはタスク終了後3分間だけ実行されます。だから私はそれが終了するまで、特定のタスクを実行したいと思います。 (docの表3-1)(アップルによって)アプリケーションがバックグラウンドモードまたはロックモードで終了してもタスクを実行する方法
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)