Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AVCaptureEventInteraction for Volume Button Shutter Capture

I've been officially notified that iOS 17.2 contains the new API to officially support volume button actuation for photo capture in a camera app.

API is called AVCaptureEventInteraction Link

So If I use the AVCam sample code, How would I be able to attach this interaction?

    if #available(iOS 17.2, *) {
       let interaction = AVCaptureEventInteraction { event in
             print ("AVCaptureEventInteraction Fired")
       }
    }

API does not contain any details.

like image 406
Gizmodo Avatar asked Dec 29 '25 07:12

Gizmodo


1 Answers

AVCaptureEventInteraction implements the UIInterAction protocol. So you should attach the AVCaptureEventInteraction to a UI element (e.g. your shutter button) that is part of the responder chain.

Example:

if #available(iOS 17.2, *) {
    let shutterEventInteraction = AVCaptureEventInteraction.init { event in
        print(event)
        if (event.phase == AVCaptureEventPhase.began) {
            self.performCapture()
        }
    }
    shutterEventInteraction.isEnabled = true
    self.shutterButton.addInteraction(shutterEventInteraction)
}
like image 200
holtmann Avatar answered Dec 30 '25 19:12

holtmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!