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.
2
Answers
You would need to integrate
AVCaptureEventInteraction
into theAVCaptureSession
or a related component.The API usage could look like this:
But, since the
AVCaptureEventInteraction
API documentation is not detailed, you might need to experiment with where to add this interaction within theAVCaptureSession
setup. A likely place is right after initializing the session and before starting it.I tried a quick search on GitHub… and found nothing(!)
You could try and add the
AVCaptureEventInteraction
initialization in theconfigureSession
method of theAVCam
sample, after setting up the session but before starting it.Inside the closure of
AVCaptureEventInteraction
, implement the logic to capture a photo when the volume button is pressed. Add the interaction to theAVCaptureSession
.Replace
self.capturePhoto()
with the actual method used in AVCam to capture a photo.AVCaptureEventInteraction
implements theUIInterAction
protocol. So you should attach theAVCaptureEventInteraction
to a UI element (e.g. your shutter button) that is part of the responder chain.Example: