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

I have a very interesting issue. I used this on a dummy application and I am able to make this portrait effect. The magic happened is when I pasted the exact code into the company application with all the properties like "Camera — Opt in for Portrait Effect", "Camera — Opt in for Reaction Effects" to YES but it is not working there.

In the above video by apple it clearly states that frame rate should be below 30fps as well as max resolution 1920 X 1440. I did made this all but still it isn't showing up on the company app. I even tried to see if the effect is support or not print("supports portraits : \(videoDevice.activeFormat.isPortraitEffectSupported)") and this prints out true.

Even tried AVCaptureDevice.showSystemUserInterface(.videoEffects) to see what is happening and it shows without portraits effects even when it is toggled on.