---
title: "register(forTaskWithIdentifier:using:launchHandler:)"
framework: backgroundtasks
role: symbol
role_heading: Instance Method
path: "backgroundtasks/bgtaskscheduler/register(fortaskwithidentifier:using:launchhandler:)"
---

# register(forTaskWithIdentifier:using:launchHandler:)

Register a launch handler for the task with the associated identifier that’s executed on the specified queue.

## Declaration

```swift
func register(forTaskWithIdentifier identifier: String, using queue: dispatch_queue_t?, launchHandler: @escaping (BGTask) -> Void) -> Bool
```

## Parameters

- `identifier`: A string containing the identifier of the task.
- `queue`: A queue for executing the task. Pass nil to 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 doc://com.apple.backgroundtasks/documentation/BackgroundTasks/BGTask object used for assigning an expiration handler and for setting a completion status. The block has no return value.

## Mentioned in

Performing long-running tasks on iOS and iPadOS

## Return value

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(_:). important: Register each task identifier only once. The system kills the app on the second registration of the same task identifier.

## See Also

### Scheduling a task

- [submit(_:)](backgroundtasks/bgtaskscheduler/submit(_:).md)
