即使应用程序处于后台或锁定模式之前,如何执行任务



在代码下方我用来在背景模式下编写某些任务。但是,在结束任务后仅执行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)

如该文档所示,仅允许允许预定义(由Apple)任务(在DOC的表3-1中)无限期地运行。在完成之前,您无法执行任务。但是,如果您将狱狱设备瞄准,则可以通过编写守护程序来做到这一点。您似乎并非如此。因此,您没有运气。

最新更新