Hey,
I am having issues with the BGProcessingTaskRequest.earliestBeginDate property.
If I use this property, my tasks are never started. Even if I wait for 24hours, with screen off and plugged in.
In this example I use 15 Minutes from now:
class func schedule() {
let request = BGProcessingTaskRequest(identifier: TASK_IDENTIFIER)
request.requiresExternalPower = false
request.requiresNetworkConnectivity = false
request.earliestBeginDate = Date(timeIntervalSinceNow: 15*60)
do {
try BGTaskScheduler.shared.submit(request)
} catch {
print("Could not schedule task: \(error)")
}
}
But if I don’t set the property earliestBeginDate and keep it at nil, my task is run without problems.
I reproduces this 3 times and the task was run after 12 Minutes, 17Minutes and 12 Minutes.
One more question: What happens to my tasks if I reenter my App before the task was run? Will they be canceled or still run?
Sometimes I see following messages in the device syslog when I reenter the app before the task was run:
Jun 10 08:23:05 Tims-iPhone My App(DuetActivityScheduler)[4118] : Will expire BGTask activities: {(
)}
Jun 10 08:23:05 Tims-iPhone My App(BackgroundTasks)[4118] : Will expire activities: {(
)}
Jun 10 08:23:05 Tims-iPhone My App(BackgroundTasks)[4118] : Calling expiration handlers for activities: {(
)}
Jun 10 08:23:05 Tims-iPhone My App(BackgroundTasks)[4118] : Calling expiration handlers for tasks: {(
)}
My Task identifier is not present in this log messages, so I guess it is not affected?