skip to Main Content

I don’t get a prompt for permissions when I run the function:
I use iOS and have this line in my info.plist

<key>NSCameraUsageDescription</key> <string>To capture profile photo please grant camera access</string>
 getPermissionStatus() async {
    await Permission.camera.request();
    var status = await Permission.camera.status;
    print(status);
    if (status.isGranted) {
      log('Camera Permission: GRANTED');
      setState(() {
        isCameraPermissionGranted = true;
      });
      // Set and initialize the new camera
      onNewCameraSelected(cameras[0]);
      refreshAlreadyCapturedImages();
    } else if (status.isPermanentlyDenied) {
      // The user opted to never again see the permission request dialog for this
      // app. The only way to change the permission's status now is to let the
      // user manually enable it in the system settings.
      openAppSettings();
    } else {
      log('Camera Permission: DENIED');
    }
  }

The Log is allways…PermissionStatus.denied

2

Answers


  1. Make sure you add camera permission in AndroidManifest
    Like:-<uses-permission android:name="android.permission.CAMERA" />
    
    Login or Signup to reply.
  2. For iOS, you need to configure following things for getting permission dialog in iOS:

    Info.plist (as your updated question you already have added this in Info.plist)

    <key>NSCameraUsageDescription</key>
    <string>To capture profile photo please grant camera access</string>
    

    Podfile (you can find this in ios folder of project)

    # Start of the permission_handler configuration
        target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
    
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
            '$(inherited)',
    
            ## dart: PermissionGroup.camera
            'PERMISSION_CAMERA=1',
          ]
    
        end
    # End of the permission_handler configuration
    

    you can find more permission group of iOS in permission_handler documentation (scroll to Setup section of ios): permission_handler

    Podfile code image

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search