iosflutterios-permissions

Can't grant the permission in Flutter iOS


I encounter a problem about the permission using Flutter. I already add the following items in iOS/Runner/Info.plist

    <key>NSCameraUsageDescription</key>
    <string>We need access to your camera to take photos.</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>We need to access your current location for manage the dispatching routing.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>We need to access your current location for manage the dispatching routing.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>We need access your microphone to talk to driver.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>For uploading driver's report including dispatch and clock in/out</string>

And call this in my code:

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

But why there is no any dialog asking for permission and when going to settings-> "App name" in my iOS device, there are no items in "Allow {App Name} to Access" for setting permission manually. All of the items don't work due to permission denied. Does I miss something? Thanks a lot.

Here is the information of flutter doctor

[✓] Flutter (Channel stable, 3.10.6, on macOS 13.6.4 22G513 darwin-x64, locale zh-Hant-TW)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio (not installed)
[✓] VS Code (version 1.62.0)
[✓] VS Code (version 1.86.1)
[✓] Connected device (2 available)
[✓] Network resources

Solution

  • Run this for adding to path:

    flutter config --android-sdk "path to your sdk root"
    

    For example

    flutter config --android-sdk "/Users/smit/androidSdk"
    

    Then this to accept the license

    flutter doctor --android-licenses
    

    For the permission issue, update your pod file

    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)',
          'PERMISSION_LOCATION=1'
          ]
        end
      end
    end