首页 > 解决方案 > 如何为 react-native-camera 使用 refreshAuthorizationStatus 函数

问题描述

我想从这里使用函数 refreshAuthorizationStatus

如果未授予许可,我还希望有一个回调。谁能帮我这个?我还没有找到一个如何调用这个函数的例子。在我的 react-native 项目中,我的相机有以下设置:

      <RNCamera
            ref={ref => {
                this.camera = ref;
            }}
            orientation='portrait'
            captureAudio={false}
            type={RNCamera.Constants.Type.front}
            flashMode={RNCamera.Constants.FlashMode.off}
            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',
            }}
            style={styles.camera}>

            <TouchableOpacity onPress={this.takePicture.bind(this)}></TouchableOpacity>
      </RNCamera>

标签: react-nativereact-native-camera

解决方案


通过以下方式授予的权限: await this.camera.refreshAuthorizationStatus()this.camera作为一个 ref 设置。

this.camera.refreshAuthorizationStatus().then(() => {
 // 
}).catch((e) =>{
// 
}):


推荐阅读