Access camera when iOS app is in background in iOS 16 and earlier

Hey, As part of a feature we are implementing in our app involves video calling. We are observed that the camera is getting interrupted whenever the app goes background.


As per apple guidelines, Apple restricts the camera usage for privacy and performance matters.


However there is an option for iOS 16 to use AVCaptureSession with isMultitaskingCameraAccessSupported 
and isMultitaskingCameraAccessEnabled 

.


For version earlier to iOS 16. we need to request an entitlement for using camera in background.


I have implemented the following logic and calling it during initialization of my view. Its an combination of swiftUI, UIViewRepresentables and UIViews.


Irrespective of using AVCaptureSession, do I need to still use entitlement for enabling this permission?


class AVCaptureSessionHelper {
  
  let captureSession = AVCaptureMultiCamSession()
  
  func startCapturingSession() {
    captureSession.beginConfiguration()
    if #available(iOS 16.0, *) {
      if captureSession.isMultitaskingCameraAccessSupported {
        captureSession.isMultitaskingCameraAccessEnabled = true
      }
    }
    captureSession.commitConfiguration()
    DispatchQueue.global(qos: .background).async {
      self.captureSession.startRunning()
    }
  }
  
  func stopCapturing() {
    DispatchQueue.global(qos: .background).async {
      self.captureSession.stopRunning()
    }
  }
}


App is unable to access camera when it is going background, Am I missing anything here?



iPhone 13

Posted on May 30, 2023 7:27 AM

Reply
2 replies

May 30, 2023 1:14 PM in response to daniel-vivek-z

daniel-vivek-z wrote:

I need to still use entitlement for enabling this permission?

Not for iOS 16 and later.

App is unable to access camera when it is going background, Am I missing anything here?

You didn't specifically say what version of iOS you are targeting or what devices you are using.


This feature is only supported on modern iPads that also support Stage Manager. Even then, its use is limited. I don't know how Apple enforces that use.


Relying on entitlements is always tricky. Often, developers assume they merely have to ask and receive. In practice, you can ask, but you may not receive. Sometimes, just the ask can trigger a new review of your apps, company, and business model. The old adage of "it never hurts to ask" does not apply to Apple.

Access camera when iOS app is in background in iOS 16 and earlier

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.