Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not responding on denying the permission #490

Closed
Uzef1997 opened this issue Aug 26, 2022 · 6 comments
Closed

Not responding on denying the permission #490

Uzef1997 opened this issue Aug 26, 2022 · 6 comments

Comments

@Uzef1997
Copy link

Describe the bug

  1. react-native-camera-kit is asking for permission to record a video that permission is irrelevant if we just want to use camera for scannig barcode or QRcode you should consider to remove a code for asking the permission or you could just ask correct permission

  2. After denying the permission I just got stuck on blank camera screen which should not be happen if user denies you should pass some callback for denying response or a promise for the same

To Reproduce
Steps to reproduce the behavior:
Use below code and click on deny when asking for permission

 <CameraScreen
    scanBarcode={true}
    showFrame={true} 
    laserColor='red' 
    frameColor='white'/>

Expected behavior
It Should throw some callback or promise reject on denying the permission and should not ask for video recording permssion

Screenshots
If the issue is a visual glitch or UI issue please provide screen shots.

Desktop (please complete the following information):
System:

  • OS: Windows 10 10.0.19042
  • CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  • Memory: 559.27 MB / 7.82 GB
    Binaries:
  • Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
  • Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
  • npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
    SDKs:
  • Android SDK:
  • API Levels: 28, 30, 33
  • Build Tools: 30.0.2, 33.0.0
  • react: 17.0.2 => 17.0.2
  • react-native: 0.69

Smartphone (please complete the following information):

  • Device: Honeywell CT60
  • OS: Android 8.1

Additional context
As a solution we can remove the native code for handling permission and use the react-native-permission for handling the permission I am attatching the code below please find it

Remove below code from node_modules/react-native-camera-kit/ios/CKCamera.m
[self handleCameraPermission];
and

-(void)handleCameraPermission {

    switch ( [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] )
    {
        case AVAuthorizationStatusAuthorized:
        {
            // The user has previously granted access to the camera.
            break;
        }
        case AVAuthorizationStatusNotDetermined:
        {
            // The user has not yet been presented with the option to grant video access.
            // We suspend the session queue to delay session setup until the access request has completed to avoid
            // asking the user for audio access if video access is denied.
            // Note that audio access will be implicitly requested when we create an AVCaptureDeviceInput for audio during session setup.
            dispatch_suspend( self.sessionQueue );
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^( BOOL granted ) {
                if ( ! granted ) {
                    self.setupResult = CKSetupResultCameraNotAuthorized;
                }
                dispatch_resume( self.sessionQueue );
            }];
            break;
        }
        default:
        {
            // The user has previously denied access.
            self.setupResult = CKSetupResultCameraNotAuthorized;
            break;
        }
    }
}

Remove below code From node_modules/react-native-camera-kit/android/CKCamera.kt

private fun hasPermissions(): Boolean {
        val requiredPermissions = arrayOf(Manifest.permission.CAMERA)
        if (requiredPermissions.all {
                    ContextCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED
                }) {
            return true
        }
        ActivityCompat.requestPermissions(
                getActivity(),
                requiredPermissions,
                42 // random callback identifier
        )
        return false
    }

replace below function

 override fun onAttachedToWindow() {
        super.onAttachedToWindow()
            viewFinder.post { setupCamera() }
    }

For the code reference with react-native-permssion look below
import { check, PERMISSIONS, RESULTS, request, openSettings } from 'react-native-permissions';

check(PERMISSIONS.ANDROID.CAMERA).then((result) => {
    switch (result) {
        case RESULTS.GRANTED:
            setPermission(true)
            break;
        
        case RESULTS.BLOCKED:
            Alert.alert("Enersense",
                "Permission has been blocked please allow it in the setting by clicking On Permission -> Camera",
                [{text: "Open Settings", 
                onPress: () => {
                    openSettings().catch(() => console.warn('cannot open settings'));
                }}])
            break
        case RESULTS.DENIED:
        case RESULTS.LIMITED:
            request(PERMISSIONS.ANDROID.CAMERA).then((requestStatus) => {
                console.log("Request status", requestStatus)
            })
        default:
            break;
    }
}).catch(error => console.log("GOT ERROR -=-=-=", error))

Please look into it and do needful
Thank you

@scarlac
Copy link
Collaborator

scarlac commented Sep 15, 2022

Great find @Uzef1997 ! We are indeed moving towards people using react-native-permissions as it's a much better solution for all the edge cases and custom prompts that modern apps must deal with.

A beta from the remove-permission-prompts branch was created that you can have a play with:
yarn add [email protected]

Since this may break features for people, I am hesitant to release it under v13. Following semver, while this is a fix for you, it would be a bug for some people.

@Uzef1997
Copy link
Author

Great find @Uzef1997 ! We are indeed moving towards people using react-native-permissions as it's a much better solution for all the edge cases and custom prompts that modern apps must deal with.

A beta from the remove-permission-prompts branch was created that you can have a play with: yarn add [email protected]

Since this may break features for people, I am hesitant to release it under v13. Following semver, while this is a fix for you, it would be a bug for some people.

could not go for the beta version as of now coz I am moving forward for production and can't take chances for beta as everything is settled with my project but surely I will try it some other time thank you for responding.

@scarlac
Copy link
Collaborator

scarlac commented Oct 5, 2022

Closing this as we have v14.0.0-beta1 with a fix for it.

@scarlac scarlac closed this as completed Oct 5, 2022
@Uzef1997
Copy link
Author

Hello @scarlac latest version still has the same issue
in my current scenario when the scanner first appears it asks for permission If I allow it then a black screen appears and nothing happens after restarting the app it works fine

second thing: when I deny for permission same screen got stuck and I did not get any callbacks or promise about the permission denial

please look into this scenarios of permission

@scarlac
Copy link
Collaborator

scarlac commented Nov 16, 2022

Hello @scarlac latest version still has the same issue

Which version did you test? Beta should have fixed this but we haven't officially released it yet.

@Uzef1997
Copy link
Author

I have tried using 13.0.0 will update here after trying beta version 14.0.0-beta2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants