Apple的AVCam演示应用程序的演示源代码位于以下位置:尝试在捕获照片的AVCamCameraViewController/CameraViewController(Swift)的行上拍照(无论构建的是Objective-C还是Swift版本)时,https://developer.apple.com/library/content/samplecode/AVCam/Introduction/Intro.html崩溃:

[self.photoOutput capturePhotoWithSettings:photoSettings delegate:photoCaptureDelegate];

或(快速)
self.photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate)

崩溃时的错误消息是:



当我检查闪光模式数组时,得到以下信息:



因此,为了添加闪存模式,文档说您必须在AVCapturePhotoSettings对象中指定要支持的模式。我已经使用以下代码行完成了此操作:
photoSettings.flashMode = AVCaptureFlashModeAuto;

或(快速)
photoSettings.flashMode = .auto

因此,我的直觉是,这是一个与12.9英寸iPad Pro特别相关的错误,我可能需要提交雷达报告,但我想如果有人之前看到它,我会在这里提出。

更新

我也能够复制其他iPad,因此它似乎不仅是12.9英寸的iPad Pro。

最佳答案

添加这个...

let position = self.videoDeviceInput.device.position
photoSettings.flashMode = position == .front || position == .unspecified ? .off : .auto

就在这之前...
self.photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate)

那应该解决问题。

关于objective-c - iPad上的AVCam项目崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40732183/

10-12 02:45