ios - Ios 中的 React-native-camera 不工作不出现

标签 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 添加到项目的构建阶段 ➜ 链接二进制文件 图书馆

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

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

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

最佳答案

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

    })

  }

关于ios - Ios 中的 React-native-camera 不工作不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56339624/

相关文章:

iphone - NSOperationQueue 并发操作与新线程开始内部操作

iphone - 解决应用内购买缺少促销代码的问题

ios - Storyboard 不允许我在 UIViewController 中选择项目

ios - 模板图像不会在启动屏幕 Storyboard上着色

iphone - 为什么仪器不执行我的 Monotouch 应用程序?

react-native - 升级到 expo 24.0.0 时调度了不受支持的顶级事件类型 "topTouchStart"

javascript - 在 React-Native 中使用 Flex-Box 对齐行

javascript - 未定义 ' this.props.navigation.state.props.p' 导航 react native

ios - Objective C 如何通过单击按钮为 subview 设置动画

ios - 如何使用核心数据存储一个值? ( swift 2)