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

🐛 Error in IOS when implementing flash: {"error": [unknown/unknown: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x281631710 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]}

Open tatianavazquez opened this issue 3 years ago • 18 comments

What were you trying to do?

I'm implementing the flash functionality.

Reproduceable Code

CAMERA MODAL COMPONENT:

const CameraModal = ({visible, setVisible}) => {
  const [headerVisible, setHeaderVisible] = useState(false);

  const closeModal = () => {
    setVisible(false);
    setPhoto('');
  };

  const { t } = useTranslation();

  return (
    <Modal
      visible={visible}
      setVisible={() => setVisible(!visible)}
      transparent={false}
      modalStyle={{
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: theme.colors.black,
        height: '100%',
      }}
    >
      <Spinner
        visible={showUntouchableOverlay}
        textContent={t('chat.loading')}
      />
      {photo ? (
        <PhotoUI
          image={{ uri: Platform.OS === 'ios' ? photo : `file://${photo}` }}
          nativeChatProps={nativeChatProps}
          onClose={closeModal}
        />
      ) : (
        <CameraUI />
      )}
    </Modal>
  );
};

export default CameraModal;


CAMERA UI:

const CameraUI = () => {
 const [photo, setPhoto] = useState('');
  const [cameraPermission, setCameraPermission] =
    useState<CameraPermissionRequestResult>();
  const camera = useRef<Camera>(null);
  const [cameraPosition, setCameraPosition] = useState<'front' | 'back'>(
    'back',
  );
  const isPressingButton = useSharedValue(false);
  const devices = useCameraDevices();
  const cameraDevice = devices[cameraPosition];

  const ReanimatedCamera = Reanimated.createAnimatedComponent(Camera);
  Reanimated.addWhitelistedNativeProps({
    zoom: true,
  });

  const setIsPressingButton = useCallback(
    (_isPressingButton: boolean) => {
      isPressingButton.value = _isPressingButton;
    },
    [isPressingButton],
  );

  const onMediaCaptured = useCallback((media: PhotoFile, type: 'photo') => {
    setPhoto(media.path);
  }, []);

  useEffect(() => {
    (async () => {
      const cameraPermissionStatus = await Camera.requestCameraPermission();
      setCameraPermission(cameraPermissionStatus);
    })();
  }, []);

  const [flash, setFlash] = useState<'off' | 'on'>('off');
  const supportsFlash = cameraDevice?.hasFlash ?? false;

  const onFlashPressed = useCallback(() => {
    setFlash(f => (f === 'off' ? 'on' : 'off'));
  }, []);

  return (
    <Container>
      <CameraHeader
        visible={headerVisible}
        flashOnPress={onFlashPressed}
        flash={supportsFlash ? flash : 'off'}
        arrowOnPress={() => setHeaderVisible(!headerVisible)}
        rawOnPress={() => console.log('TODO: Toggle raw')}
        liveOnPress={() => console.log('TODO: Toggle live')}
      />
        <ReanimatedCamera
          style={{
            width: screenWidth,
            height: screenHeight * 0.75,
          }}
          device={cameraDevice}
          isActive
          ref={camera}
          photo
          enableZoomGesture={false}
          animatedProps={cameraAnimatedProps}
          onError={error => {
            console.log({ error });
          }}
        />
      <Buttons>
        <ButtonsComponents.PhotoGalleryButton
          onPress={() => console.log('TODO: open gallery')}
        />
        <ButtonsComponents.CaptureButton
          camera={camera}
          onMediaCaptured={onMediaCaptured}
          cameraZoom={zoom}
          minZoom={minZoom}
          maxZoom={maxZoom}
          flash={supportsFlash ? flash : 'off'}
          enabled
          setIsPressingButton={setIsPressingButton}
        />
        <ButtonsComponents.ChangeCameraButton
          onPress={() => console.log('TODO: change camera')}
        />
      </Buttons>
    </Container>
  )
};

export default CameraUI;

What happened instead?

Sometimes when I click on the flash icon, the camera turns black and nothing happens until I click on the icon again. The console.log for 'error' on the Camera, gives me this error:

LOG {"error": [unknown/unknown: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x280d5bdb0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]}

This error logs whenever I click on the camera icon.

Relevant log output

No response

Device

iPhone 13

VisionCamera Version

^2.15.4

Additional information

tatianavazquez avatar May 30 '23 00:05 tatianavazquez

I am facing the same issue, any updates? I am able to repro if I take two pictures right after each other.

thunderousNinja avatar Jun 11 '23 11:06 thunderousNinja

No, I don't have any updates and I don't know why this is happening... :/ where can we get help?

tatianavazquez avatar Jun 11 '23 18:06 tatianavazquez

Try this https://www.youtube.com/playlist?list=PLQhQEGkwKZUrempLnmxjt7ZCZJu1W3p2i

myselfuser1 avatar Jun 12 '23 03:06 myselfuser1

Same

alessandrom avatar Jul 05 '23 07:07 alessandrom

Hey - hmm maybe the device does not support flash?

mrousavy avatar Aug 03 '23 07:08 mrousavy

Closing as this is a stale issue - this might have been fixed with the full rewrite in VisionCamera V3 (🥳) - if not, please create a new issue.

If your issue has been fixed, consider sponsoring me on GitHub to say thanks 💖

mrousavy avatar Sep 30 '23 10:09 mrousavy

Hello, @mrousavy Still facing below error.


[unknown/unknown: Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed" UserInfo={NSLocali
zedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x300f15590 {Error Domain=NS
OSStatusErrorDomain Code=-12780 "(null)"}}]

I'm using this version. "react-native-vision-camera": "4.6.3",

DarshanSavaliyaGitHub avatar Mar 10 '25 13:03 DarshanSavaliyaGitHub

Still facing this issue only on iOS physical device while trying to access front camera:

[unknown/unknown: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x3024523d0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]

"react-native-vision-camera": "^4.6.4"

mgulfam0722 avatar Apr 24 '25 04:04 mgulfam0722

Still facing this issue on iOS physical device both camera: [unknown/unknown: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x3024523d0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]

"react-native-vision-camera": "^4.6.4" "react-native": "0.75.4",

info.plist:

<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
	<key>NSAllowsLocalNetworking</key>
	<true/>
</dict>

NSCameraUsageDescription App requires access to your camera to capture photos and record videos for product sharing and virtual try-ons. NSMicrophoneUsageDescription App requires access to your microphone to record audio for video reviews and live shopping sessions.

when call camera.current.startRecording still got that err. Have any update :(

khanwilson avatar May 10 '25 11:05 khanwilson

Hello, The root cause of this issue, as per my observation, is that you might have unmounted the screen which contains the <Camera /> component which causes this error. For example, using navigation methods like navigation.replace() or navigation.resetStack will unmount the screen component and any preceding screen containing the <Camera /> component will throw the mentioned error.

mgulfam0722 avatar May 12 '25 06:05 mgulfam0722

Hello, The root cause of this issue, as per my observation, is that you might have unmounted the screen which contains the <Camera /> component which causes this error. For example, using navigation methods like navigation.replace() or navigation.resetStack will unmount the screen component and any preceding screen containing the <Camera /> component will throw the mentioned error.

hmm, it not true with my situation. <Camera /> is on a modal. it have call in a FormCreate Screen. And both of them still in stack. But still got err: Error Domain=AVFoundationErrorDomain Code=-11800. Still record without sound

khanwilson avatar May 12 '25 07:05 khanwilson

Hello, The root cause of this issue, as per my observation, is that you might have unmounted the screen which contains the <Camera /> component which causes this error. For example, using navigation methods like navigation.replace() or navigation.resetStack will unmount the screen component and any preceding screen containing the <Camera /> component will throw the mentioned error.

hmm, it not true with my situation. <Camera /> is on a modal. it have call in a FormCreate Screen. And both of them still in stack. But still got err: Error Domain=AVFoundationErrorDomain Code=-11800. Still record without sound

Perhaps, you can verify if your screen component/modal, containing the <Camera /> component, is being unmounted using useEffect hook like this:

useEffect(() => {
    console.log('screen mounted!');
    return () => {
        console.log('Unmounted!');
    }
}, []);

mgulfam0722 avatar May 12 '25 09:05 mgulfam0722

This error can also occur when you audio file is corrupted, empty, Doesn't exists or any unsupported configurations. Example: Unsupported Sample rate, bit depth, To test try to replace with a test audio file..

ani-backend avatar Jul 25 '25 15:07 ani-backend

@ani-backend Which audio file you're talking about ?

i recently updated my react-native project. removed react-native-camera and added react-native-vision-camera i need video with audio but audio={true} throwing error

Karina5Aryan avatar Aug 13 '25 10:08 Karina5Aryan

I'm facing the same problem with version 4.7.1. I believe @mgulfam0722 is right on his observation. I also noticed the same situation. In my case this error happens when rotating the device (as I remount the component). Did you find a solution for this?

williamgurzoni avatar Sep 02 '25 23:09 williamgurzoni

@ani-backend Which audio file you're talking about ?

i recently updated my react-native project. removed react-native-camera and added react-native-vision-camera i need video with audio but audio={true} throwing error

Getting exactly same error but this only happen in iOS "react-native-vision-camera": "^4.7.0",

allanmnolasco avatar Sep 15 '25 16:09 allanmnolasco

I'm facing the same problem with version 4.7.1. I believe @mgulfam0722 is right on his observation. I also noticed the same situation. In my case this error happens when rotating the device (as I remount the component). Did you find a solution for this?

@williamgurzoni Have you found any solution yet? Let me know.

las-dungnm avatar Sep 25 '25 02:09 las-dungnm

I'm facing the same problem with version 4.7.1. I believe @mgulfam0722 is right on his observation. I also noticed the same situation. In my case this error happens when rotating the device (as I remount the component). Did you find a solution for this?

@williamgurzoni Have you found any solution yet? Let me know.

In my case the error was happening when rotating the device. In fact after many attempts I figured out that the problem was with React re-rendering the camera component, which was causing it to remount. So I fixed my case by refactoring the way the component works and avoiding re-rendering the camera. But I believe that there is still something going on here.

williamgurzoni avatar Sep 25 '25 02:09 williamgurzoni