How to enable the Portrait Effect in live camera view similar to SnapChat?

I have a camera view based on AVFoundation. Any idea how I can switch to Portrait Effect in iOS's Control Center like SnapChat?

Replies

Opting your app in to the Portrait effect is covered in this video, the link is timestamped to the relevant section: https://developer.apple.com/videos/play/wwdc2021/10047/?time=1324

In short, unless your iOS app is a VoIP app, you need to explicitly opt-in by adding the "NSCameraPortaitEffectEnabled" key to your info.plist with a value of "YES". This key also comes up as the "Camera — Opt in for Portrait Effect" key in Xcode.

  • Thanks for the reply. I set the "Camera — Opt in for Portrait Effect" key to YES but when I swipe up in the app to see the Control Center there is still no Video Effects" option. Also, I am calling AVCaptureDevice.showSystemUserInterface(.videoEffects) inside the app with a button but it shows me a full-screen blurred view with two camera icons (one large and the other small), nothing like the photo which I posted in the question. Any idea what is happening?

  • Not every capture format supports the Portrait effect, you should iterate through the supported formats array of your AVCaptureDevice, and choose a format (set it as the activeFormat) that reports true for the isPortraitEffectSupported property.

Add a Comment