register(forTaskWithIdentifier:using:launchHandler:)
Register a launch handler for the task with the associated identifier that’s executed on the specified queue.
Declaration
func register(forTaskWithIdentifier identifier: String, using queue: dispatch_queue_t?, launchHandler: @escaping (BGTask) -> Void) -> BoolParameters
- identifier:
A string containing the identifier of the task.
- queue:
A queue for executing the task. Pass
nilto use a default background queue. - launchHandler:
The system runs the block of code for the launch handler when it launches the app in the background. The block takes a single parameter, a Bgtask object used for assigning an expiration handler and for setting a completion status. The block has no return value.
Mentioned in
Return value
Returns true if the launch handler was registered. Returns false if the identifier isn’t included in the BGTaskSchedulerPermittedIdentifiers Info.plist.
Discussion
Every identifier in the BGTaskSchedulerPermittedIdentifiers requires a handler. Registration of all launch handlers must be complete before the end of applicationDidFinishLaunching(_:).