I am using BGProcessingTaskRequest to fetch a API make my app up to date. Sometimes this background task execute with 10 minutes some times it take more than 10 mins, Some other times its never execute.
But in my case im provide just 1 minute to BGProcessingTaskRequest.earliestBeginDate variable. And i will share my implementation here,
My codes are,
Called the register function before app launching.
let taskId = "_________"
func registerBackgroundTaks() {
BGTaskScheduler.shared.register(forTaskWithIdentifier: taskId, using: nil) { task in
self.handleBackgroundProcessRequest(task: task as! BGProcessingTask)
}
print("Receiver called")
}
Called the scheduleBackgroundPrecessingTask function when application enter in background mode.
func scheduleBackgroundPrecessingTask() {
let request = BGProcessingTaskRequest(identifier: taskId)
request.requiresNetworkConnectivity = false // Need to true if your task need to network process. Defaults to false.
request.requiresExternalPower = false
request.earliestBeginDate = Date(timeIntervalSinceNow: 1 * 60) // Featch Image Count after 1 minute.
do {
try BGTaskScheduler.shared.submit(request)
print("Process notification triggered")
} catch {
print("Could not schedule background process: \(error)")
}
}
Could anyone share any concerns to my problem? or kindly clarify me why BGProcessingTaskRequest takes time randomly?
Before you continue, please read iOS Background Execution Limits.
Sometimes this background task execute with 10 minutes some times it take more than 10 mins
That doesn’t surprise me. A background processing task (created with BGProcessingTaskRequest
) is not guaranteed to run on any particular schedule. Rather, the schedule is an implementation detail. I typically see these run overnight.
This is the same issue that my app faces with iOS18
Are you talking about a processing task (BGProcessingTaskRequest
) or an app refresh task (BGAppRefreshTaskRequest
)?
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"