【问题标题】:React-native-camera in Ios not working not appearingIos中的React-native-camera不工作没有出现
【发布时间】:2019-05-28 09:58:49
【问题描述】:

使用库 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 并转到构建设置选项卡。确保打开“全部”(而不是 '基本')。

  • 在 Search Paths 部分,查找 Header Search Paths 并确保它同时包含 $(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)
         }
       };
    

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

【问题讨论】:

    标签: ios iphone react-native


    【解决方案1】:
    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 })
    
        })
    
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多