Flutter-permission-handler: [BUG][iOS] Permission Popup not being displayed

Created on 7 Sep 2020  Â·  19Comments  Â·  Source: Baseflow/flutter-permission-handler

On iOS, on either a real or a simulated device, the iOS popup for accepting the permission is not being displayed.
On Android everything is working right. On iOS, running the command await permission.request() returns PermissionStatus.undetermined without showing the popup.

I've strictly followed the steps specified on pub.dev page, on my current project and on a new project created just for this.
It use to work in a previous build I've made of the same code about 1 month ago (I don't remember which version of Flutter and PermissionHandler was using).

My Flutter doctor output is:

Flutter (Channel stable, 1.20.3, on Mac OS X 10.15.6 ...)
Android toolchain - develop for Android devices (Android SDK version 30.0.0)
Xcode - develop for iOS and macOS (Xcode 12.0)
Android Studio (version 4.0)
Connected device (1 available)

No issues found!

Anyone has any helpful info?
I will gladly give any additional info :)!

Thank you!

Most helpful comment

Hi @Faiizii, since the permission handler ^8.0.0 some things have changed with the Podfile. Have you read the new documentation which can be found here?

It used to be that the # was necessary to have in front of the permission you do want to use, this has been changed now.
Now you should remove the # in front of the permission you do want to use.

For example:

You want to use the camera, make sure your Podfile contains the following code:

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

your plist.info should contain:

<!-- Permission options for the `camera` group -->
    <key>NSCameraUsageDescription</key>
    <string>camera</string>

Do you have that in your files?

If you do, you should be possible to just use Permission.camera.request() and it should give you the dialog for the permission.

If this didn't help, can you try to run flutter clean first and build the project again?

If that didn't help I would like to see a code snippet where you ask for the permission, and your plist and Podfile would be useful.

Thanks in advance!

All 19 comments

Same here.
Flutter 1.20.3
Permission handler 5.0.1+1

Podfile contains

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      # You can remove unused permissions here
      # for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/permission_handler/ios/Classes/PermissionHandlerEnums.h
      # e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.calendar
        'PERMISSION_EVENTS=0',

        ## dart: PermissionGroup.reminders
        'PERMISSION_REMINDERS=0',

        ## dart: PermissionGroup.contacts
        'PERMISSION_CONTACTS=0',

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

        ## dart: PermissionGroup.microphone
        # 'PERMISSION_MICROPHONE=0',

        ## dart: PermissionGroup.speech
        'PERMISSION_SPEECH_RECOGNIZER=0',

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

        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        # 'PERMISSION_LOCATION=0',

        ## dart: PermissionGroup.notification
        'PERMISSION_NOTIFICATIONS=0',

        ## dart: PermissionGroup.mediaLibrary
        'PERMISSION_MEDIA_LIBRARY=0',

        ## dart: PermissionGroup.sensors
        'PERMISSION_SENSORS=0'
      ]
    end    
  end
end

The call to .request() returns immediately with with status not granted. Permission popup never displays.

    bool allowed = await Permission.locationWhenInUse.isGranted;
    if (allowed == false) {
      logger.info('permission is not granted, requesting location permission.');
      final PermissionStatus status =
          await Permission.locationWhenInUse.request();
      allowed = status.isGranted;
    }

I found that if I go to Settings > Privacy > Location Services and look at my app, it was set to While Using. I changed it to Ask Next Time. When I ran the app, the popup worked. Somehow it was not respecting the setting.

I found that if I go to Settings > Privacy > Location Services and look at my app, it was set to While Using. I changed it to Ask Next Time. When I ran the app, the popup worked. Somehow it was not respecting the setting.

Not for me. In my case, in Settings it does not even appear as the app needs that permission.

@mvanbeusekom
same issue , I go to Settings > Privacy > Location Services not exists event i have add in to info.plist
how come when i request permission pop up not appears when i try request again got error "Unhandled Exception: PlatformException(ERROR_ALREADY_REQUESTING_PERMISSIONS, A request for permissions is already running, please wait for it to finish before doing another request"
pop not appears but log say already request permissions

same here

I have the same problem. Is there any solution?

Same here. And many other tickets on the same issue appear under this plugin.
Developers are not responding :-( This is a show stopper level bug and app is useless in iOS without permissions.
As there is no response to these issues by the dev team is it safe to assume this plugin is no longer maintained?

I also encountered the same problem, how to solve it?

add the following lines in info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location when in use</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Always and when in use!</string>
<key>NSLocationUsageDescription</key>
<string>Older devices need location.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Can I haz location always?</string>

I am having the same problem. All the keys are set. Android is working perfectly

I've tried to reproduce the steps, but for me the pop-up does show, and I can set the permission status to granted or to denied. The steps I took to reproduce are as follow:

  1. Created a test app by typing in the terminal flutter create test_app
  2. I added permission_handler: ^6.1.1 in the pubspec.yaml
  3. Run flutter pub get
  4. In the info.plist I added the permission I wanted to add (I tested it with the location as mentioned by @tmorone-rezi)
    `` <!-- Permission options for thelocation` group -->
    NSLocationWhenInUseUsageDescription
    Need location when in use
    NSLocationAlwaysAndWhenInUseUsageDescription
    Always and when in use!
    NSLocationUsageDescription
    Older devices need location.
    NSLocationAlwaysUsageDescription
    Can I have location always?
5. in the ```pod file```  I added the following lines:

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
# You can remove unused permissions here
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/permission_handler/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',

    ## dart: PermissionGroup.calendar
    'PERMISSION_EVENTS=0',

    ## dart: PermissionGroup.reminders
    'PERMISSION_REMINDERS=0',

    ## dart: PermissionGroup.contacts
    'PERMISSION_CONTACTS=0',

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

    ## dart: PermissionGroup.microphone
    'PERMISSION_MICROPHONE=0',

    ## dart: PermissionGroup.speech
    'PERMISSION_SPEECH_RECOGNIZER=0',

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

    ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
    # 'PERMISSION_LOCATION=0',

    ## dart: PermissionGroup.notification
    'PERMISSION_NOTIFICATIONS=0',

    ## dart: PermissionGroup.mediaLibrary
    'PERMISSION_MEDIA_LIBRARY=0',

    ## dart: PermissionGroup.sensors
    'PERMISSION_SENSORS=0'
  ]
end
(Notice how only 'PERMISSION_LOCATION' has a '#' in front of it, since we want to check for the location permission)

6. In the default example .dart file which will be created using the command in step 1, I added the code in the _incrementCounter(), the code I used was submitted by submitted by @tmorone-rezi.

bool allowed = await Permission.locationWhenInUse.isGranted;

if (allowed == false) {
  final PermissionStatus status =
      await Permission.locationWhenInUse.request();
  allowed = status.isGranted;
}

```

  1. Run pod install
  2. Run app on emulator

This did show the permission pop-up which, and the status was set to the correct status.


flutter doctor -v
[✓] Flutter (Channel stable, 2.0.4, on macOS 11.1 20C69 darwin-x64, locale
nl-NL)
• Flutter version 2.0.4 at /Users/jan-derk/Documents/Baseflow/flutter
• Framework revision b1395592de (7 days ago), 2021-04-01 14:25:01 -0700
• Engine revision 2dce47073a
• Dart version 2.12.2

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/jan-derk/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses

[!] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade see
https://guides.cocoapods.org/using/getting-started.html#installation for
instructions.

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
• iPhone 12 Pro Max (mobile) • 55D9F3D7-ACF6-4CDA-8AFD-1F67CDE2C027 • ios
• com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
• Chrome (web) • chrome •
web-javascript • Google Chrome 89.0.4389.114

! Doctor found issues in 2 categories.

If people are still facing this issue using the newest plugin version, please let us know. Also please provide a small example code so we can try to reproduce the issue. thanks in advance!

thanks @JDDV
I don't know, why I think the opposite with the instruction
" e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0' ". So if I want to use the camera, so the podfile will look like this:

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

Still with the #

Hi @IkhwanSI13, yes indeed. The # should be in front of the permission you do want to use. This had me confused the first time too, I'm glad I could help!

Still facing this issue. Here is the flutter --version result and using permission_handler: ^8.0.0+2
Flutter 2.0.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision 1d9032c7e1 (4 weeks ago) • 2021-04-29 17:37:58 -0700 Engine • revision 05e680e202 Tools • Dart 2.12.3
I have declared the permissions in the info-plist in the form of key pairs. But code do not popup the permission request dialog (working in android). I checked the setting of the app in my iPhone and found no permission declared there.
Any help will be appreciated Thanks in advance

Hi @Faiizii, since the permission handler ^8.0.0 some things have changed with the Podfile. Have you read the new documentation which can be found here?

It used to be that the # was necessary to have in front of the permission you do want to use, this has been changed now.
Now you should remove the # in front of the permission you do want to use.

For example:

You want to use the camera, make sure your Podfile contains the following code:

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

your plist.info should contain:

<!-- Permission options for the `camera` group -->
    <key>NSCameraUsageDescription</key>
    <string>camera</string>

Do you have that in your files?

If you do, you should be possible to just use Permission.camera.request() and it should give you the dialog for the permission.

If this didn't help, can you try to run flutter clean first and build the project again?

If that didn't help I would like to see a code snippet where you ask for the permission, and your plist and Podfile would be useful.

Thanks in advance!

@JDDV JD
i'm facing another issue.
i am using "permission_handler: ^8.0.0+1"
and added

## dart: PermissionGroup.camera PERMISSION_CAMERA=1', on Podfile, and <!-- Permission options for thecameragroup --> <key>NSCameraUsageDescription</key> <string>camera</string>

In ios: when I select "don't allow" in the dialog for permissions. permission status is permanentlyDenied (expect has just been denied). So it doesn't show the dialog again, it asks openAppSettings to change permissions.
in android: everything is ok

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.0.3, on Mac OS X 10.15 19A583 darwin-x64, locale en) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [!] Xcode - develop for iOS and macOS ! Xcode 11.2.1 out of date (12.0.1 is recommended). Download the latest version or update via the Mac App Store. [✓] Chrome - develop for the web [✓] Android Studio (version 3.5) [✓] Connected device (3 available)

Solution i had a same problem in permission_handler: ^8.0.0+2, but after update version with permission_handler: 7.1.0 it show a location request popup now.

Hi @hungnv1709, thanks for your questions, The reason why you're having this behaviour is mentioned in this issue and in this issue. So this behaviour is as expected

Hi @hungnv1709, In iOS, if user denied the permission in first attempt (willingly or accidently), next time user have to allow the permission from the setting of the app. However in android, you can still open the permission dialog until the user choose never ask again option,

Was this page helpful?
0 / 5 - 0 ratings