问题描述
我正在尝试使用来自“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
解决方法
添加 captureAudio={false}
以绕过此错误。
<RNCamera
...
captureAudio={false}
>
</RNCamera>