Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(props) {
super(props);
this.updateIsAuthorized = this.updateIsAuthorized.bind(this);
let isAuthorized = true;
if (Platform.OS === 'ios') {
// Asks for permissions if not defined, returns choice otherwise
isAuthorized = undefined;
Camera.checkDeviceAuthorizationStatus().then(this.updateIsAuthorized);
}
this.state = { isAuthorized };
this.onQRCodeScanned = _.debounce(props.onQRCodeScanned, 1000, { leading: true, trailing: false });
}
takePicture = async function () {
if (Host.isIOS) {
if (!await Camera.checkDeviceAuthorizationStatus()) {
alert('相机权限未开启')
return
}
}
if (Host.isAndroid) {
if (!await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA)) {
alert('相机权限未开启')
return
} else {
console.log('相机权限已开启');
}
}
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
login (){
const { navigator } = this.props;
if(Platform.OS == 'ios'){
Camera.checkDeviceAuthorizationStatus().then( (isAuth) =>{
if(isAuth){
navigator.push({
component : QrCode
})
}else{
actions.toast('请在设置中开启Noder对相机的访问')
}
}).catch( (err) =>{
actions.toast('获取相机访问权错误');
})
}else{
navigator.push({
component : QrCode
})
}
grantCameraPermission = async () => {
try {
if (Platform === 'ios' || Platform.OS === 'ios') {
const permission = await Camera.checkDeviceAuthorizationStatus();
this.setState({ loading: false, permissionDenied: !permission });
} else {
const cameraGranted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA);
const interalStorageGranted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
const externalStorageGranted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
if (cameraGranted === PermissionsAndroid.RESULTS.GRANTED
&& interalStorageGranted === PermissionsAndroid.RESULTS.GRANTED
&& externalStorageGranted === PermissionsAndroid.RESULTS.GRANTED) {
this.setState({ loading: false, permissionDenied: false });
} else {
this.setState({ loading: false, permissionDenied: true });
}
}