---
title: "addTarget(handler:)"
framework: mediaplayer
role: symbol
role_heading: Instance Method
path: "mediaplayer/mpremotecommand/addtarget(handler:)"
---

# addTarget(handler:)

Adds a block to be called when an event is received.

## Declaration

```swift
func addTarget(handler: @escaping (MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus) -> Any
```

## Parameters

- `handler`: A block object to handle the doc://com.apple.mediaplayer/documentation/MediaPlayer/MPRemoteCommandEvent.

## Return Value

Return Value An opaque object associated with the designated handler.

## Discussion

Discussion Call the addTarget(handler:) method to add a block to be called. Remove the handler by calling the removeTarget(_:) method, passing in the object returned by this method.

## See Also

### Handling events

- [addTarget(_:action:)](mediaplayer/mpremotecommand/addtarget(_:action:).md)
- [removeTarget(_:)](mediaplayer/mpremotecommand/removetarget(_:).md)
- [removeTarget(_:action:)](mediaplayer/mpremotecommand/removetarget(_:action:).md)
- [MPRemoteCommandHandlerStatus](mediaplayer/mpremotecommandhandlerstatus.md)
