---
title: AVCaptureEventInteraction
framework: avkit
role: symbol
role_heading: Class
path: avkit/avcaptureeventinteraction
---

# AVCaptureEventInteraction

An object that registers handlers to respond to capture events from system hardware buttons.

## Declaration

```swift
@MainActor class AVCaptureEventInteraction
```

## Overview

Overview The system Camera app allows people to perform capture functions by pressing hardware buttons on their iOS device. UIKit apps can add similar functionality by using this type to register handlers that respond to interactions from device hardware. note: In SwiftUI, respond to capture events from hardware buttons using onCameraCaptureEvent(isEnabled:action:) and onCameraCaptureEvent(isEnabled:primaryAction:secondaryAction:) instead. The following example shows how to add a handler that captures a photo when a user presses a hardware button on their device. class CameraViewController: UIViewController {          /// An object that manages the camera functionality.     private let camera = CameraModel()          /// A capture event interaction to handle hardware button presses.     private var eventInteraction: AVCaptureEventInteraction?          override func viewDidLoad() {         super.viewDidLoad()         // Configure the app to take a photo on hardware button press.         configureHardwareInteraction()     }          private func configureHardwareInteraction() {         // Create a new capture event interaction with a handler that captures a photo.         let interaction = AVCaptureEventInteraction { [weak self] event in             // Capture a photo on "press up" of a hardware button.             if event.phase == .ended {                 self?.camera.capturePhoto()             }         }         // Add the interaction to the view controller's view.         view.addInteraction(interaction)         eventInteraction = interaction     } } The event handler queries the capture event to determine its phase, and when the interaction ends, captures a photo. important: You can only use this API for capture use cases. The system sends capture events only to apps that actively use the camera. Backgrounded capture apps, and apps not performing capture, don’t receive events. Adopting this API overrides default hardware button behavior, so apps must always respond appropriately to any events received. Failing to handle events results in a nonfunctional button that provides a poor user experience. If your app is temporarily unable to handle events, disable the interaction by setting its isEnabled property to false, which restores the system button behavior.

## Topics

### Creating an interaction

- [init(handler:)](avkit/avcaptureeventinteraction/init(handler:).md)
- [init(primary:secondary:)](avkit/avcaptureeventinteraction/init(primary:secondary:).md)

### Inspecting the interaction

- [isEnabled](avkit/avcaptureeventinteraction/isenabled.md)
- [defaultCaptureSoundDisabled](avkit/avcaptureeventinteraction/defaultcapturesounddisabled.md)

### Initializers

- [init(eventHandler:)](avkit/avcaptureeventinteraction/init(eventhandler:).md)
- [init(primaryEventHandler:secondaryEventHandler:)](avkit/avcaptureeventinteraction/init(primaryeventhandler:secondaryeventhandler:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [UIInteraction](uikit/uiinteraction.md)

## See Also

### iOS playback and capture

- [Playing video content in a standard user interface](avkit/playing-video-content-in-a-standard-user-interface.md)
- [AVPlayerViewController](avkit/avplayerviewcontroller.md)
- [AVPlayerViewControllerDelegate](avkit/avplayerviewcontrollerdelegate.md)
- [AVCaptureEvent](avkit/avcaptureevent.md)
- [AVCaptureEventSound](avkit/avcaptureeventsound.md)
- [AVInputPickerInteraction](avkit/avinputpickerinteraction.md)
- [Third-party casting support](avkit/third-party-casting-support.md)
