submitTaskRequest
NewiOStvOSwatchOSopen func submitTaskRequest(_ taskRequest: BGTaskRequest, completionHandler: @escaping @Sendable ((any Error)?) -> Void)Submits a background task request to be scheduled with a completion handler.
This method asynchronously submits the task request and invokes the completion handler with any errors that occur during submission.
Submitting a task request for an unexecuted task that's already in the queue replaces the previous task request.
There can be a total of 1 refresh task and 10 processing tasks scheduled at any time. Trying to schedule more tasks will result in an error with code BGTaskSchedulerErrorCodeTooManyPendingTaskRequests.
Common errors include:
BGTaskSchedulerErrorCodeNotPermitted: Task identifier not permitted or unsupported resources requestedBGTaskSchedulerErrorCodeTooManyPendingTaskRequests: Too many pending tasks of this typeBGTaskSchedulerErrorCodeUnavailable: Background refresh disabled or app not permittedBGTaskSchedulerErrorCodeImmediateRunIneligible: Immediate run not eligible due to system conditions
The completion handler is called on an arbitrary queue.
Note: The completion handler may be invoked on a arbitrary queue after an arbitrary amount of delay. Do not call this method from the main thread or performance-critical contexts.
This method replaces the deprecated submitTaskRequest:error: method
Parameters
taskRequest- The task request object representing the parameters of the background task to be scheduled.
completionHandler- A block that is called when submission completes. The block receives an optional error parameter: -
nilif the task was submitted successfully - AnNSErrorif submission failed