I have a react-native application that uses react-native-camera with its FaceDetection functionality and was working smoothly for quite some time. Lately it started to shut down unexpectedly every time you try to open camera in this app. Code wasn't change. And for android it still works fine.
I saw that react-native-camera became deprecated, but I'm not sure why it started causing this issue. Looks like some FaceDetection support broken or is missing. I'm testing on iPhone 13 with iOS 15 (both device and simulator)
Here's the exception itself:
...
in ForwardRef
in RCTView
in RCTView
in o
in Unknown
in RCTView
in RCTView
in C
2022-05-01 16:38:35.567685+0200 AppName[34604:2942356] *** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: TypeError: undefined is not an object (evaluating 'p.RNCamera.Constants.FaceDetection.Mode.accurate')
Here's usage:
import React, {useState, useEffect} from 'react';
import {
View,
StyleSheet,
TouchableHighlight,
Platform,
Alert,
} from 'react-native';
import {SVGIcon} from '../common/svg/SVG';
import {useNavigation} from '@react-navigation/native';
import DropDownPicker from 'react-native-dropdown-picker';
import Svg from 'react-native-svg';
import LinearGradient from 'react-native-linear-gradient';
import {CitySelect} from '../common/Types';
import {StyledText} from '../common/StyledText';
import {useUser} from '../common/UserData';
import {fontName, cities, isHigherDimension} from '../common/common';
import {RNCamera} from 'react-native-camera';
...
<RNCamera
ref={rnCamera}
style={styles.preview}
trackingEnabled
captureAudio={false}
useNativeZoom={true}
type={RNCamera.Constants.Type.back}
flashMode={flashMode}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}
androidRecordAudioPermissionOptions={{
title: 'Permission to use audio recording',
message: 'We need your permission to use your audio',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}
onFacesDetected={facesDetected}
faceDetectionMode={
RNCamera.Constants.FaceDetection.Mode.accurate
}></RNCamera>
Dependencied in my package.json
"@react-native-community/masked-view": "^0.1.10",
"@react-native-firebase/analytics": "^7.6.2",
"@react-native-firebase/app": "^8.4.2",
"@types/react-native": "^0.62.2",
"react": "16.11.0",
"react-native": "0.62.2",
"eslint": "^6.5.1",
"react-native-camera": "^4.2.1",
What I tried to do
First of all, I tried to check those RNCamera.Constants Options that appears to be undefined. Here's the value
this one is empty
"FaceDetection":{
},
but this one is present
"GoogleVisionBarcodeDetection":{
"BarcodeMode":{
"ALTERNATE":1,
"INVERTED":2,
"NORMAL":0
},
"BarcodeType":{
}
}
As well I tried to remove the line that is calling RNCamera.Constants.FaceDetection.Mode.accurate constant. Then I get Exception thrown while executing UI block: -[FaceDetectorManagerMlkit setTracking:queue:]: unrecognized selector sent to instance 0x281eb18e0
.
I started to migrate to latest react-native, I got too much errors, it failed in many places so I decided to put this option aside.
I do have the line pod 'react-native-camera', path: '../node_modules/react-native-camera', subspecs: [ 'FaceDetector']
in my pod file. I tried to reinstall pods/rebuild multiple times.
Somewhere I saw recommendations to use Xcode "legacy build system" - no luck.
I tried manual linking of react native camera, still no success, as well as unlinking and reinstalling.
I'd really like to keep the functionality of face detection, so I'm looking forward to any suggestions! What could be the reason, has something in iOS changed that might've caused it?