赞
踩
#import <React/RCTBridgeModule.h>
@interface CameraPermissionManager : NSObject <RCTBridgeModule>
@end
#import "CameraPermissionManager.h" #import <AVFoundation/AVCaptureDevice.h> @implementation CameraPermissionManager RCT_EXPORT_MODULE(); RCT_EXPORT_METHOD(checkCameraStatus:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (status == AVAuthorizationStatusAuthorized) { resolve(@"authorized"); } else if (status == AVAuthorizationStatusNotDetermined) { resolve(@"undetermined"); } else if(status == AVAuthorizationStatusDenied || status == AVAuthorizationStatusRestricted){ resolve(@"rejected"); } else { resolve(@"denied"); } } @end
import {NativeModules} from 'react-native';
export default NativeModules.CameraPermissionManager;
import cameraPermiss from '../cameraPermiss.js' //判断用户是否相机授权 const cameraPermiss = async () => { if (Platform.OS == 'android') { const response = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA); console.log("[相机授权]", response) if (response != 'granted') { //用户拒绝 Linking.openSettings(); } } else { const response = await cameraPermiss.checkCameraStatus(); console.log("[相机授权]", response) if (response == 'rejected') { //用户拒绝 Linking.openSettings(); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。