BGTaskScheduler 因“BGTaskSchedulerErrorDomain”而失败 - 代码:iOS 13.0 上的 1
我已经尝试过 Apple 提供的示例程序 ColorFeed,它也面临同样的问题
let request = BGProcessingTaskRequest(identifier: "com.example.apple-samplecode.ColorFeed.db_cleaning")
request.requiresNetworkConnectivity = false
request.requiresExternalPower = true
do
{
try BGTaskScheduler.shared.submit(request)
} catch {
print("Could not schedule database cleaning: \(error)")
}
上面的代码在 applicationDidEnterBackground 中被调用
早些时候,该任务已在 didFinishLaunchingWithOptions ...
BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.example.apple-samplecode.ColorFeed.db_cleaning", using: nil) { task in
// Downcast the parameter to a processing task as this identifier is used for a processing request.
self.handleDatabaseCleaning(task: task as! BGProcessingTask)
}