react-native-qrcode-scanner-view icon indicating copy to clipboard operation
react-native-qrcode-scanner-view copied to clipboard

第一次进入路由页面没有相机权限就会直接闪退

Open Tyrone2333 opened this issue 6 years ago • 8 comments

第一次进入路由页面没有相机权限就会直接闪退,请问需要怎么处理?

Tyrone2333 avatar Oct 16 '19 07:10 Tyrone2333

兄弟 那个版本的?

zkkg2018 avatar Oct 16 '19 07:10 zkkg2018

兄弟 那个版本的?

^2.0.0,现在我用 react-native-camera 官方的 demo + 这个库的 QRScannerRectView 不会闪退了

Tyrone2333 avatar Oct 17 '19 01:10 Tyrone2333

需要先申请权限,再跳转扫码,否则会因为权限不足报错。你自己加个 react-native-permissions 库判断下应该就好了。

MarnoDev avatar Nov 09 '19 02:11 MarnoDev

@MarnoDev 请问是判断 PERMISSIONS.ANDROID.CAMERA 吗 判断后在Android模拟器第一次打开正常,但是退出再次打开白屏,并且打包后Android真机闪退,是我判断错误还是需要判断别的权限

import {check, PERMISSIONS, RESULTS, request} from 'react-native-permissions';

check(Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA).then(result => {
                            switch (result) {
                                case RESULTS.UNAVAILABLE:
                                    console.log('This feature is not available (on this device / in this context)',);
                                    break;
                                case RESULTS.DENIED:
                                    console.log('开始请求权限');
                                    request(Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA).then(result => {
                                        if(result){
                                            this.props.navigation.navigate('Scanner')
                                        }
                                    });
                                    break;
                                case RESULTS.GRANTED:
                                    console.log('已通过');
                                    this.props.navigation.navigate('Scanner')
                                    break;
                                case RESULTS.BLOCKED:
                                    console.log('The permission is denied and not requestable anymore');
                                    break;
                                }
                            })

Don-oneself avatar Nov 13 '19 11:11 Don-oneself

QRScanner.js
组件 RNCamera 添加权限

androidCameraPermissionOptions={{
                        title:'****',
                        message: '****',
                        buttonPositive: '****',
                        buttonNegative: '****',
                    }}

但是有一个很神奇的现象 连续开关七八次 就闪退了

Don-oneself avatar Nov 15 '19 01:11 Don-oneself

@MarnoDev 请问是判断 PERMISSIONS.ANDROID.CAMERA 吗 判断后在Android模拟器第一次打开正常,但是退出再次打开白屏,并且打包后Android真机闪退,是我判断错误还是需要判断别的权限

import {check, PERMISSIONS, RESULTS, request} from 'react-native-permissions';

check(Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA).then(result => {
                            switch (result) {
                                case RESULTS.UNAVAILABLE:
                                    console.log('This feature is not available (on this device / in this context)',);
                                    break;
                                case RESULTS.DENIED:
                                    console.log('开始请求权限');
                                    request(Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA).then(result => {
                                        if(result){
                                            this.props.navigation.navigate('Scanner')
                                        }
                                    });
                                    break;
                                case RESULTS.GRANTED:
                                    console.log('已通过');
                                    this.props.navigation.navigate('Scanner')
                                    break;
                                case RESULTS.BLOCKED:
                                    console.log('The permission is denied and not requestable anymore');
                                    break;
                                }
                            })

用了你的代码,完美解决了我的问题啦,哈哈哈!!!

weiting918 avatar Dec 04 '19 02:12 weiting918

@weiting918 不闪退吗? 增加 react-native-permissions 插件,不如在 RNCamera 添加权限

Don-oneself avatar Dec 04 '19 02:12 Don-oneself

How to fix when we must request permission in qrcode scanner screen?

nguyentuanit97 avatar Oct 13 '20 03:10 nguyentuanit97