开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜