react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

✨ Enable multitasking camera access on iOS

Open ethul opened this issue 1 year ago • 4 comments

What feature or enhancement are you suggesting?

Would it be possible to add support for enabling multitasking camera access?

This would be useful for apps running on iPads with Stage Manager or Split View/Slide Over turned on.

From the Apple developer documentation I tried adding the following to the camera session, which seemed to do the trick.

if #available(iOS 16.0, *) {
  if self.captureSession.isMultitaskingCameraAccessSupported {
    // Enable use of the camera in multitasking modes.
    self.captureSession.isMultitaskingCameraAccessEnabled = true
  }
}

What Platforms whould this feature/enhancement affect?

iOS

Alternatives/Workarounds

I manually made the change in Core/CameraSession.swift.

Additional information

ethul avatar Sep 25 '24 18:09 ethul

Guten Tag, Hans here! 🍻

Zis feature request for enabling multitasking camera access on iOS is interesting, and it looks like you already made some attempts! However, we need a bit more information to evaluate zis properly. It would be helpful if you could provide any logs or error messages you encountered while implementing zis feature.

Also, if you appreciate ze work we do on zis repository, consider sponsoring the project to help us keep it going! Support mrousavy on GitHub Sponsors.

Let's keep ze conversation going!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

maintenance-hans[bot] avatar Sep 25 '24 18:09 maintenance-hans[bot]

Without the change to enable multitasking, when Stage Manager or Split View/Slide Over was turned on, the camera preview was blank, and recording a video issued an error:

capture/unknown: Error Domain=AVFoundationErrorDomain Code=-11803 "Cannot Record" UserInfo={AVErrorRecordingFailureDomainKey=3, NSLocalizedDescription=Cannot Record, NSLocalizedRecoverySuggestion=Try recording again.}

ethul avatar Sep 26 '24 18:09 ethul

Hey! Oh, pretty cool. Yea I can add that feature if I have some free time soon, thanks for posting the code here this is really helpful.

mrousavy avatar Oct 01 '24 19:10 mrousavy

Great, thanks!

ethul avatar Oct 03 '24 20:10 ethul

+1 on this, I have CameraRuntimeError's every now and then when another task interrupts the camera. Not 100% sure if this would fix the problem, but it couldn't hurt! Sometimes, this also creates a video recording with no audio when another video in the background hijacks the audio session.

ChristopherGabba avatar Oct 28 '24 11:10 ChristopherGabba

Reading the docs wouldn't hurt - this is already true if you have the entitlement for it (which is required, and would crash otherwise)

Screenshot 2024-10-29 at 09 23 56

mrousavy avatar Oct 29 '24 08:10 mrousavy

I think it is important to note that the multitaasking-camera-access entitlement is deprecated.

Screen Shot 2024-10-30 at 10 27 50 AM

It seems like the recommended approach is to use isMultitaskingCameraAccessEnabled.

ethul avatar Oct 30 '24 14:10 ethul