类型错误:CameraManager.checkIfRecordAudioPermissionsAreDefined 不是函数

Posted

技术标签:

【中文标题】类型错误:CameraManager.checkIfRecordAudioPermissionsAreDefined 不是函数【英文标题】:TypeError: CameraManager.checkIfRecordAudioPermissionsAreDefined is not a function 【发布时间】:2021-01-08 20:46:02 【问题描述】:

我正在尝试使用“react-native-camera”中的组件RNCamera,但在我接受我的应用程序使用我的相机的权限后,我收到此错误:

[Unhandled promise rejection: TypeError: CameraManager.checkIfRecordAudioPermissionsAreDefined is not a function. (In 'CameraManager.checkIfRecordAudioPermissionsAreDefined()', 'CameraManager.checkIfRecordAudioPermissionsAreDefined' is undefined)]
* http://packager.ms-zi8.anonymous.reactnativeclient.exp.direct/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&minify=false:423779:99 in requestPermissions$
- node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:293:29 in invoke
- node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:154:27 in invoke
- node_modules\regenerator-runtime\runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

我正在渲染的组件

import React,  useEffect, useRef, useState  from 'react';
import  TouchableOpacity, ViewStyle, Text, View  from 'react-native';
import theme from '../Theme/theme';

// Components
import Box from './core/Box';
import  RNCamera  from 'react-native-camera';

type Props = 



const TakeMedia = (: Props) => 
  const cameraRef = useRef();

  // const takePicture = async () => 
  //   if (cameraRef.current) 
  //     const options =  quality: 0.5, base64: true ;
  //     const data = await camera.takePictureAsync(options);
  //     console.log(data.uri);
  //   
  // ;

  return (
    <View style= styles.container as ViewStyle >
      <RNCamera
        // @ts-ignore
        ref=cameraRef
        style= styles.preview as ViewStyle 
        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',
        
      />
      <View style= flex: 0, flexDirection: 'row', justifyContent: 'center' >
        <TouchableOpacity style= styles.capture as ViewStyle >
          <Text style= fontSize: 14 > SNAP </Text>
        </TouchableOpacity>
      </View>
    </View>
  )
;

const styles = 
  container: 
    flex: 1,
    flexDirection: 'column',
    backgroundColor: 'black',
  ,
  preview: 
    flex: 1,
    justifyContent: 'flex-end',
    alignItems: 'center',
  ,
  capture: 
    flex: 0,
    backgroundColor: '#fff',
    borderRadius: 5,
    padding: 15,
    paddingHorizontal: 20,
    alignSelf: 'center',
    margin: 20,
  ,


export default TakeMedia;

我已经尝试过这个解决方案RNCamera Error:TypeError: CameraManager.checkIfRecordAudioPermissionsAreDefined is not a function

【问题讨论】:

【参考方案1】:

添加captureAudio=false 以绕过此错误。

<RNCamera
    ...
    captureAudio=false
>
</RNCamera>

【讨论】:

以上是关于类型错误:CameraManager.checkIfRecordAudioPermissionsAreDefined 不是函数的主要内容,如果未能解决你的问题,请参考以下文章

js错误类型

js常见错误类型

错题本上的常见错误类型及改正方法

Flutter fromJson - 未处理的错误未处理的错误类型'String'不是'int'类型的子类型发生在实例中

我在尝试登录或注册时收到错误消息“错误类型‘AuthResult’不是类型转换中‘FirebaseUser’类型的子类型”

ASP.NET MVC前台解析JSON时,类型错误