开发者

How to re request permission camera and reload the permission library using react native qrcode scanner?

开发者 https://www.devze.com 2022-12-07 21:39 出处:网络
I want to re request permission camera when permission from library is denied by user. I have using this function to check permission and re request if permission is denied;

I want to re request permission camera when permission from library is denied by user. I have using this function to check permission and re request if permission is denied;

const checkPermissionCamera = async () => {
    const permission = await PermissionsAndroid.check(
        PermissionsAndroid.PERMISSIONS.CAMERA,
    );
    if (!permission) {
      PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.CAMERA,
      ).finally(() => {
        refQR.current?.reactivate();
      });
    }

    refQR.current?.reactivate();
  };

And this is how i called the qrcode scanner component

<QRCodeScanner
          ref={(node) => {
            refQR.current = node;
          }}
          reactivateTimeout={2000}
          onRead={(scanData) => {
            console.log(scanData
          }}
          flashMode={RNCamera.Constants.FlashMode.auto}
          showMarker
          fadeIn
          cameraStyle={{
            height: '100%',
  开发者_开发知识库        }}
        />

When user choose the permission that i have request, the qr code scanner just loading and won't re check the permission. Anyone have solution?


if the user previously denied the permission then no library can request the permission again. your library will always return 'denied' so use alert and on ok of alert open Linking.openSettings() and ask user to grant access.

0

精彩评论

暂无评论...
验证码 换一张
取 消