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