如何检查 Swift 中是否支持 AVCaptureSession 预设分辨率

How to check if AVCaptureSession preset resolution is supported in Swift

例如,我可能想将它设置为 hd1280x720,但前提是它受支持,并使用其他情况下受支持的较低分辨率。

session = AVCaptureSession()
if(**my device supports hd1280x720**){
  session!.sessionPreset = AVCaptureSession.Preset.hd1280x720
}else if(**my device supports 640x480**){
  session!.sessionPreset = AVCaptureSession.Preset.vga640x480
}

使用AVCaptureSession.canSetSessionPreset(_:):

Returns a Boolean value that indicates whether the receiver can use the given preset.