BGTaskScheduler fails with "BGTaskSchedulerErrorDomain" - code: 1 on iOS 13.0
I have tried the sample program ColorFeed made available by Apple and it faces the same issue
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)")
}
The above code gets called in applicationDidEnterBackground
Earlier the task is registered in 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)
}
In my case I had to run the app in Release mode to get it to work.
Edit Scheme -> Build configuration -> Release