Crash when using front camera ONLY on pre-iPhone 7 devices

后端 未结 1 987
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 20:06

I\'ve recently started running beta on my camera-based app. Everything is working as expected except on iPhone 6 devices.

The session starts on the back camera, and each

相关标签:
1条回答
  • 2021-01-24 20:43

    captureSession.addInput(videoInput) is causing the crash.

    So you should use canAddInput(_:) before to avoid the crash.

    if captureSession.canAddInput(videoInput) {
        captureSession.addInput(videoInput)
    }
    

    And in your case, captureSession.canAddInput(videoInput) == false with that iPhone 6.

    Now, you are also doing self.captureSession.sessionPreset = .hd1920x1080

    But according to WikiPedia, the iPhone 6 Front Camera hardware supports camera 1.2 MP (1280×960 px max.), 720p video recording (30 fps). Doesn't seem to fit the 1920*1080 ("Full HD").

    You could do this check what the "max" AVCaptureSession.Preset you can use.

    func setSessionPreset(forDevice device: AVCaptureDevice) {
        let videoPresets: [AVCaptureSession.Preset] = [.hd4K3840x2160, .hd1920x1080, .hd1280x720] //etc. Put them in order to "preferred" to "last preferred"
        let preset = videoPresets.first(where: { device.supportsSessionPreset($0) }) ?? .hd1280x720
        captureSession.sessionPreset = preset
    }
    
    0 讨论(0)
提交回复
热议问题