Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native-camera in Ios not working not appearing

Making a demo for text Recognition with camera using library react-native-camera but camera is not opening

DONE ALL THESE STEPS:

npm install react-native-camera --save
react-native link react-native-camera
  • Go to node_modules ➜ react-native-camera and add RNCamera.xcodeproj
  • Expand the RNCamera.xcodeproj ➜ Products folder
  • In XCode, in the project navigator, select your project. Add libRNCamera.a to your project's Build Phases ➜ Link Binary With Libraries

  • Click RNCamera.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic').

  • In the Search Paths section, look for Header Search Paths and make sure it contains both $(SRCROOT)/../../react-native/React and $(SRCROOT)/../../../React - mark both as recursive

    import { RNCamera } from 'react-native-camera'; 
    
    camerascan(){
     console.log("camscan=====")
     return(
    
       <RNCamera
       ref={ref => {
         this.camera = ref;
       }}
       defaultTouchToFocus
       mirrorImage={false} 
       captureAudio={false}
       style={{
         flex: 1,
         justifyContent: 'space-between',
         alignItems: 'center',
         height: Dimensions.get('window').height,
         width: Dimensions.get('window').width,
       }}
    
       permissionDialogTitle={'Permission to use camera'}
       permissionDialogMessage={'We need your permission to use your camera phone'}
    
    
     >
          <View
               style={{
                 height: 56,
                 backgroundColor: 'transparent',
                 alignSelf: 'flex-end',
               }}
             >
      <TouchableOpacity onPress={this.takePicture.bind(this)}>
         <Text style={styles.capture}> [CAPTURE CARD]</Text>
         </TouchableOpacity>
         </View>
     </RNCamera>  
    
     );
    
    }
       takePicture = async function() {
         console.log("takePicture=====")
         if (this.camera) {
          // const options = { quality: 0.5, base64: true };
           // const data = await this.camera.takePictureAsync(options)
           const data = await this.camera.takePictureAsync();
           console.warn('takePicture ', data);
           // this.detectText(data.base64)
         }
       };
    

No error but camera is not opening.

like image 926
deepanshu katyal Avatar asked Apr 15 '26 11:04

deepanshu katyal


1 Answers

Done gave the  runtime permissions for camera

import Permissions from 'react-native-permissions'

 componentDidMount()
 {
    this.determinePermission();
  }
  determinePermission(){    
    Permissions.request('camera', { type: 'always' }).then(response => {
      this.setState({ locationPermission: response })

    })

  }
like image 70
deepanshu katyal Avatar answered Apr 18 '26 00:04

deepanshu katyal