【发布时间】:2019-11-03 13:25:03
【问题描述】:
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)
}
【问题讨论】:
标签: ios swift backgroundtaskidentifier