4

To record video, while setting video codec as below:

sessionOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecTypeJPEG]

XCode says 'AVVideoCodecTypeJPEG' has been renamed to 'AVVideoCodecType.jpeg' and 'AVVideoCodecTypeJPEG' was obsoleted in Swift 3 and it suggests Replace 'AVVideoCodecTypeJPEG' with 'AVVideoCodecType.jpeg'

After doing that, XCode says 'jpeg' is only available on iOS 11.0 or newer.

The problem is I have to use iOS 10 and want to use Swift 4.

Is there any solution to use features like this in Swift 4 with iOS 10?

1 Answer 1

13

I think the right way to solve such issue is to use the new AVVideoCodecType.jpeg and the deprecated one AVVideoCodecJPEG, doing so:

if #available(iOS 11.0, *) {
    sessionOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecType.jpeg]
} else {
    sessionOutput.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]
}
Sign up to request clarification or add additional context in comments.

1 Comment

I thought I did it and it threw an error! But when I copied your code it works. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.