我已经被正式通知,iOS 17.2包含了新的API,正式支持在相机应用程序中对照片捕捉的音量按钮激活.

接口名为AVCaptureEventInteraction Link

那么,如果我使用AVCam sample code,我将如何能够附加此交互组件?

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

接口不包含任何详细信息.

推荐答案

You would need to integrate AVCaptureEventInteraction into the AVCaptureSession or a related component.
The API usage could look like this:

if #available(iOS 17.2, *) {
    let interaction = AVCaptureEventInteraction { event in
        // Handle the volume button press event here
        // e.g., Trigger photo capture
        print("AVCaptureEventInteraction Fired")
    }
    // Add the interaction to your capture session or related component
    // That might depend on further details from the API documentation
    captureSession.addInteraction(interaction)
}

But, since the AVCaptureEventInteraction API documentation is not detailed, you might need to experiment with where to add this interaction within the AVCaptureSession 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 the configureSession method of the AVCam 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 the AVCaptureSession.

func configureSession() {
    // existing setup code for AVCaptureSession 

    if #available(iOS 17.2, *) {
        let interaction = AVCaptureEventInteraction { event in
            // Implement the logic to capture a photo
            print("AVCaptureEventInteraction Fired")
            // Example: self.capturePhoto()
        }
        captureSession.addInteraction(interaction)
    }

    // rest of the session configuration 
}

self.capturePhoto()替换为AVCam中用于拍摄照片的实际方法.

Ios相关问答推荐

在SwiftUI中使用系统图像和色调创建圆形按钮

在带有可编码的SWIFT5中,可以轻松处理以美元符号开头的JSON密钥,例如$DATE";

当重新呈现UI时,嵌套的 struct 值如何与@Observable一起工作?

AVFoundation Camera推出变焦SWIFT

iOS 17-在Xcode 15中添加导航控制器时,导航栏不会立即显示

使用 WebKit 加载 YouTube 视频时控制台中打印警告

如何链式设置 AttributeContainer 的 UIKit 属性?

尽管存在浮点错误,如何显示正确的计算结果.计算器应用程序

Flutter iOS 构建失败:DVTCoreDeviceEnabledState_Disabled

核心媒体基础知识,了解 CMSampleBuffer、CMBlockBuffer 和 CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer

@MainActor 类的扩展是主要演员吗?

为什么 Swift 不在启动的同一线程上恢复异步函数?

Text() 正在添加额外的前导尾随填充 SwiftUI

如何为视图的 colored颜色 和宽度设置动画?

从父母到子元素的 Swift Pass 事件

使用实时数据库的应用程序无法在被 Firebase 阻止的罗马尼亚 ISP 中运行

Swift:调用中缺少参数标签xxx

iOS 7 圆形框架按钮

如何关闭 iOS 键盘?

在 iOS 7 中更改返回按钮会禁用滑动导航返回