iOS中的React-Native-Camera无法正常工作

时间:2019-05-28 09:58:50

标签: ios iphone react-native

使用库react-native-camera使用相机进行文本识别演示,但相机没有打开

完成所有这些步骤:

npm install react-native-camera --save
react-native link react-native-camera
  • 转到node_modules➜react-native-camera并添加RNCamera.xcodeproj
  • 展开RNCamera.xcodeproj➜Products文件夹
  • 在XCode的项目导航器中,选择您的项目。将libRNCamera.a添加到项目的Build Phases➜Link Binary With 图书馆

  • 在项目导航器中单击RNCamera.xcodeproj,然后转到“构建设置”选项卡。确保已启用“全部”(而不是 “基本”)。

  • 在“搜索路径”部分中,查找标题搜索路径,并确保它同时包含$(SRCROOT)/../../ react-native / React和 $(SRCROOT)/../../../ React-都标记为递归

    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)
         }
       };
    

没有错误,但相机没有打开。

1 个答案:

答案 0 :(得分:0)

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 })

    })

  }