react-native-camera使用注意事项

本文介绍了如何在React-Native项目中使用react-native-camera组件,并详细阐述了在Android 6.0及以上版本手动申请相机权限的步骤,包括在XML中配置权限以及在组件中设置权限选项。同时,提到了苹果iOS平台申请相机权限的方法,需在Xcode中修改项目设置。正确配置权限是避免使用相机功能时应用闪退的关键。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

react-native-camera的地址:https://github.com/react-native-camera/react-native-camera/blob/master/docs/RNCamera.md

Android 6.0以上需要自己手动申请权限

Android申请权限方式参考官方说明:

<RNCamera
          ref={ref => {
            this.camera = ref;
          }}
          style={styles.preview}
          type={RNCamera.Constants.Type.back}
          flashMode={RNCamera.Constants.FlashMode.on}
          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',
          }}
          onGoogleVisionBarcodesDetected={({ barcodes }) => {
            console.log(barcodes);
          }}
        />

苹果也需要申请权限:

苹果申请相机权限的操作为:打开ios下的.xcodeproj文件,使用Xcode打开项目,然后选择target,选择info,找到Privacy-Camera Usage Description, Type自动为String,value就自己填写就行

如果不配置相机权限,那么使用react-native-camera进行拍照或者扫码的时候会闪退

我的项目是react native0.68版本的react-native-sunmi-inner-printer这个依赖需要那个版本能够兼容我的项目 以下是我的json文件中的一段 "dependencies": { "@ant-design/icons-react-native": "^2.3.2", "@ant-design/react-native": "^5.0.1", "@react-native-async-storage/async-storage": "^1.19.0", "@react-native-community/cameraroll": "^4.0.0", "@react-native-community/masked-view": "0.1.11", "@react-native-community/segmented-control": "^2.1.1", "@react-native-community/slider": "^3.0.3", "@react-native-community/viewpager": "^4.1.6", "@react-native-picker/picker": "^1.16.8", "@react-navigation/native": "^6.1.7", "@react-navigation/native-stack": "^6.9.12", "@rneui/base": "^4.0.0-rc.7", "@rneui/themed": "^4.0.0-rc.8", "@taoqf/react-native-mqtt": "^3.0.4", "d3-shape": "^1.3.7", "minio": "^7.0.15", "react": "17.0.2", "react-dom": "^17.0.2", "react-native": "0.68.0", "react-native-background-timer": "^2.4.1", "react-native-device-info": "^8.1.3", "react-native-elements": "^1.2.7", "react-native-exception-handler": "^2.10.10", "react-native-fs": "^2.18.0", "react-native-gesture-handler": "^1.10.3", "react-native-get-location": "^2.1.0", "react-native-get-random-values": "^1.4.0", "react-native-image-picker": "^3.8.1", "react-native-image-zoom-viewer": "^3.0.1", "react-native-linear-gradient": "^2.8.3", "react-native-modal-dropdown": "^1.0.2", "react-native-permissions": "3.8.0", "react-native-reanimated": "2.14.4", "react-native-safe-area-context": "3.3.2", "react-native-screens": "3.15.0", "react-native-signature-canvas": "^4.1.0", "react-native-signature-capture": "^0.4.12", "react-native-sound": "^0.11.1", "react-native-sqlite-storage": "^4.1.0", "react-native-svg-charts": "5.4.0", "react-native-table-component": "^1.2.2", "react-native-thermal-receipt-printer": "^1.2.0-rc.2", "react-native-vector-icons": "^9.2.0", "react-native-web": "^0.17.1", "react-native-webview": "^11.26.0", "react-redux": "^7.2.0", "redux": "^4.0.5", "redux-thunk": "^2.3.0" }, 我需要安装react-native-sunmi-inner-printer那个版本才能兼容我的项目,安装这个react-native-sunmi-inner-printer能够兼容的版本后还需不需要其他的依赖一块来安装。
最新发布
08-02
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晒干的老咸鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值