【问题标题】:React native camera fails to renderReact 本机相机无法渲染
【发布时间】:2021-08-01 22:28:51
【问题描述】:

我对 RNCamera 有疑问。它以前可以工作,但现在停止了,我不知道为什么。 问题是它没有被渲染,没有显示请求权限的弹出窗口,我可以在日志中看到这个错误:

Possible Unhandled Promise Rejection (id: 3):
TypeError: CameraManager.checkVideoAuthorizationStatus is not a function
TypeError: CameraManager.checkVideoAuthorizationStatus is not a function
    at requestPermissions$ (/home/pro/Documents/app/.vscode/.react/index.bundle:143969:61)
    at tryCatch (/home/pro/Documents/app/.vscode/.react/index.bundle:25021:19)
    at Generator.invoke [as _invoke] (/home/pro/Documents/app/.vscode/.react/index.bundle:25194:24)
    at Generator.next (/home/pro/Documents/app/.vscode/.react/index.bundle:25064:23)
    at tryCatch (/home/pro/Documents/app/.vscode/.react/index.bundle:25021:19)
    at invoke (/home/pro/Documents/app/.vscode/.react/index.bundle:25094:22)
    at /home/pro/Documents/app/.vscode/.react/index.bundle:25124:13
    at tryCallTwo (/home/pro/Documents/app/.vscode/.react/index.bundle:27110:7)
    at doResolve (/home/pro/Documents/app/.vscode/.react/index.bundle:27274:15)
    at new Promise (/home/pro/Documents/app/.vscode/.react/index.bundle:27133:5)

RNCamera 是这样使用的:

import { RNCamera } from 'react-native-camera';
...
<RNCamera
  style={{ flex: 1 }}
  captureAudio={false}
  ref={(cam) => {
    this.camera = cam;
  }}
  barCodeTypes={[
    RNCamera.Constants.BarCodeType.aztec,
    RNCamera.Constants.BarCodeType.qr,
    RNCamera.Constants.BarCodeType.datamatrix,
  ]}
  onBarCodeRead={this.onSuccessQrScan}
  notAuthorizedView={
    <View style={StylesGlobal.container}>
      <Icon name="close" size={60} color={Color.RED} style={{ alignSelf: 'center' }} />
      <TextCenter small>{strings.general.cameraNotAuthorized}</TextCenter>
    </View>
  }
  androidCameraPermissionOptions={{
    title: strings.general.cameraPermissionTitle,
    message: strings.general.cameraPermission,
    buttonPositive: strings.general.ok,
    buttonNegative: strings.general.cancel,
  }}
/>
...

react-native 版本是 0.63.2

react-native-camera 版本是 3.23.1

我尝试按照here 的描述使用手动安装,但收到模块链接两次的错误,我没有克服。

你能帮忙吗?如果您需要我可以提供的任何其他来源。

谢谢

编辑:

我发现了奇怪的事情。 RNCamera 在应用程序中的 2 个不同地方使用,有时它可以在 1 个地方工作,但从不会在其他地方工作,并出现描述的错误。

EDIT2:

我已经按照here 此处所述成功手动安装了 react-native-camera,并且还解决了 this 链接两次但结果相同的模块问题

【问题讨论】:

    标签: android react-native react-native-camera


    【解决方案1】:

    我认为 react-native 链接 react-native-camera 没有按预期工作。手动链接库将解决问题。 对于您的错误 - 模块已链接两次 - 首先取消链接与 react-native-camera 相关的所有内容,然后使用文档再次添加手动链接。

    【讨论】:

    • AFAIK 自 RN > 0.60 自动链接已完成,所以我没有这样做 react-native link react-native-camera
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多