3

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?

Update:

Created a clean projects to test out this example code, Implemented the permission_handler to force the permissions (based on recommendation from @cenk-yagmur).

The permissions window now comes up, however the example code still doesn't work.

This leads me to believe it is either:

  1. The camera package doesn't work on iOS16
  2. The example code is wrong.

I'm more inclined towards 2. Will be doing a custom integration and test if that fixes the issue.

T J
  • 659
  • 1
  • 8
  • 18

4 Answers4

2

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;
    }
  }
}
rasityilmaz
  • 764
  • 1
  • 6
  • 11
  • Tried this and unfortunately it didn't make any difference. – T J Dec 01 '22 at 13:11
  • If the permission is permanently denied, the permission dialog will not open again. You know that right? – rasityilmaz Dec 01 '22 at 13:56
  • yes of course. As I had mentioned in my original question those settings were not granted, nor were they even present in the settings. – T J Dec 02 '22 at 05:10
  • Also tried this update to the podfile, and have it as an implementation in one of my other apps, although it made no difference this time. – Chris Feb 23 '23 at 10:52
0

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();
Cenk YAGMUR
  • 3,154
  • 2
  • 26
  • 42
  • I haven't implemented the permission_handler, simply because the camera package and the flutter docs, don't explicitly ask for the permission_handler package. – T J Dec 01 '22 at 10:47
  • I had the same problem and couldn't find any other solution. – Cenk YAGMUR Dec 01 '22 at 11:01
  • Yes, so I implemented this package to see if it triggers the permissions. And it does! But strangely the example code still doesn't work, it still returns a null list of cameras. I even did a print of the list of cameras and it seems to be showing a list, however now I'm suspecting that the example code itself is flawed. – T J Dec 02 '22 at 05:11
  • `cameras = await availableCameras();` Doesn't it throw an error when you import it into the try catch blog after getting the permissions? – Cenk YAGMUR Dec 02 '22 at 07:39
0

For me what worked was to remove the permission_handler package all together and rely on the exceptions the camera package throws. I hope this helps

-1

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

powerman23rus
  • 1,297
  • 1
  • 9
  • 17
  • Then it would show up in the app settings OR the Settings>Privacy & Security>Camera However it is not showing there. – T J Dec 01 '22 at 10:38