录制视频,同时设置视频编解码器如下:
sessionOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecTypeJPEG]
XCode说'AVVideoCodecTypeJPEG' has been renamed to 'AVVideoCodecType.jpeg'
和'AVVideoCodecTypeJPEG' was obsoleted in Swift 3
,它建议Replace 'AVVideoCodecTypeJPEG' with 'AVVideoCodecType.jpeg'
完成后,XCode说'jpeg' is only available on iOS 11.0 or newer
。
问题是我必须使用iOS 10并且想要使用Swift 4.
在iOS 10的Swift 4中是否有使用此类功能的解决方案?
答案 0 :(得分:11)
我认为解决此类问题的正确方法是使用新的AVVideoCodecType.jpeg
和弃用的AVVideoCodecJPEG
,这样做:
if #available(iOS 11.0, *) {
sessionOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecType.jpeg]
} else {
sessionOutput.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]
}