Flutter IOS camera permission not working for permission_handler package

265 Views Asked by At

I have added permission_handler 11.1.0 package in my flutter App. package link According to their documentation, I have added these codes in PodFile for installer:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.camera
        'PERMISSION_CAMERA=1',

        ## dart: PermissionGroup.photos
        'PERMISSION_PHOTOS=1',

        ## dart: PermissionGroup.mediaLibrary
        # 'PERMISSION_MEDIA_LIBRARY=1',
        ]
    end
  end
end

#Default installer commented
# post_install do |installer|
#   installer.pods_project.targets.each do |target|
#     flutter_additional_ios_build_settings(target)
#   end
# end

I have also added these keys in Info.plist file:

<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>This App requires access to your phone’s camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This App requires Photo permission.</string>

But, when I run my app in IOS simulator, Gallery permission and image picking from gallery working just fine, but Camera permission not showing at all and camera cannot be opened! What have I missed?

Note: My flutter version 3.16.3 • channel stable, Dart 3.2.3, DevTools 2.28.4

I tried to run my flutter app's camera permission using permission_handler package. I expect to show camera permission in the app same as Android. But actually in result, when I wants to take camera permission, It shows "Forever denied" always & no camera permission showing

1

There are 1 best solutions below

0
AQ Nahid On

Solved! Updated PodFile's post_install:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.camera
        'PERMISSION_CAMERA=1',

        ## dart: PermissionGroup.photos
        'PERMISSION_PHOTOS=1',

        ## dart: PermissionGroup.mediaLibrary
        # 'PERMISSION_MEDIA_LIBRARY=1',
        ]
    end
    flutter_additional_ios_build_settings(target)
  end
end

#Default installer commented
# post_install do |installer|
#   installer.pods_project.targets.each do |target|
#     flutter_additional_ios_build_settings(target)
#   end
# end

Working fine now