Home > front end >  Flutter iOS - Not asking for Camera permission
Flutter iOS - Not asking for Camera permission

Time:12-01

Implemented the example from the camera package here:

https://pub.dev/packages/camera/example

While testing on the physical device (running iOS 16), the app builds and runs fine, however the phone does not ask for any permissions to access the camera or microphone.

The following code has been added to ios/Runner/Info.plist

<key>NSCameraUsageDescription</key>
<string>Testing the Camera integration.</string>
<key>NSMicrophoneUsageDescription</key>
<string>To add sounds to the videos you record.</string>

The iOS Deployment Target has been set to iOS 11.0

Note: I can assure you that the app has not been granted these permissions already because:

  1. It is not showing up in the app settings
  2. The app is not listed in Settings>Privacy & Security>Camera

Am I missing something?

CodePudding user response:

If the system not asking the permission than it was granted before

CodePudding user response:

https://pub.dev/packages/permission_handler

To avoid problems, have it checked before accessing the camera to see if it has permission.

Map<Permission, PermissionStatus> statuses = await [
  Permission.camera,
  Permission.microphone,
].request();

CodePudding user response:

You can add this code to the PodFile and try again.

Don't forget to clean, pub get and pod install.

Remember just turn off the comment line for the properties you are using and set the value to 1.

   post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
                   '$(inherited)',
    
                   ## dart: PermissionGroup.calendar
                   ##'PERMISSION_EVENTS=1',
    
                   ## dart: PermissionGroup.reminders
                   #'PERMISSION_REMINDERS=0',
    
                   ## dart: PermissionGroup.contacts
                   # 'PERMISSION_CONTACTS=0',
    
                   ## dart: PermissionGroup.camera
                   'PERMISSION_CAMERA=1',
    
                   ## dart: PermissionGroup.microphone
                   'PERMISSION_MICROPHONE=1',
    
                   ## dart: PermissionGroup.speech
                   #'PERMISSION_SPEECH_RECOGNIZER=0'
    
                   ## dart: PermissionGroup.photos
                   'PERMISSION_PHOTOS=1',
    
                   ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
                   'PERMISSION_LOCATION=1',
    
                   ## dart: PermissionGroup.notification
                   'PERMISSION_NOTIFICATIONS=1',
    
                   ## dart: PermissionGroup.appTrackingTransparency
                    ##'PERMISSION_APP_TRACKING_TRANSPARENCY=1',
    
                   ## dart: PermissionGroup.mediaLibrary
                   ##'PERMISSION_MEDIA_LIBRARY=1'
    
                   ## dart: PermissionGroup.sensors
                   #'PERMISSION_SENSORS=0'
                 ]
        end
      end
    end

My Photos and Camera permissions function code:

Future<bool?> _checkPermission(BuildContext context) async {
  if (Platform.isAndroid) {
    Map<Permission, PermissionStatus> statues = await [Permission.camera, Permission.photos].request();
    PermissionStatus? statusCamera = statues[Permission.camera];

    PermissionStatus? statusPhotos = statues[Permission.photos];
    bool isGranted = statusCamera == PermissionStatus.granted && statusPhotos == PermissionStatus.granted;
    if (isGranted) {
      return true;
    }
    bool isPermanentlyDenied = statusCamera == PermissionStatus.permanentlyDenied || statusPhotos == PermissionStatus.permanentlyDenied;
    if (isPermanentlyDenied) {
      return false;
    }
  } else {
    Map<Permission, PermissionStatus> statues = await [Permission.camera, Permission.storage, Permission.photos].request();
    PermissionStatus? statusCamera = statues[Permission.camera];
    PermissionStatus? statusStorage = statues[Permission.storage];
    PermissionStatus? statusPhotos = statues[Permission.photos];
    bool isGranted = statusCamera == PermissionStatus.granted && statusStorage == PermissionStatus.granted && statusPhotos == PermissionStatus.granted;
    if (isGranted) {
      return true;
    }
    bool isPermanentlyDenied = statusCamera == PermissionStatus.permanentlyDenied || statusStorage == PermissionStatus.permanentlyDenied || statusPhotos == PermissionStatus.permanentlyDenied;
    if (isPermanentlyDenied) {
      return false;
    }
  }
}
  • Related