Contents

submitTaskRequest(_:completionHandler:)

Submits a background task request to be scheduled with a completion handler.

Declaration

func submitTaskRequest(_ taskRequest: BGTaskRequest, completionHandler: @escaping  @Sendable ((any Error)?) -> Void)
func submitTaskRequest(_ taskRequest: BGTaskRequest) async throws

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:

    • nil if the task was submitted successfully

    • An NSError if submission failed

Discussion

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 BGTaskScheduler.Error.Code.tooManyPendingTaskRequests.

Common errors include:

The completion handler is called on an arbitrary queue.

This method replaces the deprecated submit(_:) method