Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] permission alert not displayed on Retry #718

Closed
erperejildo opened this issue Nov 2, 2021 · 3 comments
Closed

[iOS] permission alert not displayed on Retry #718

erperejildo opened this issue Nov 2, 2021 · 3 comments
Labels
platform: ios Issue is related to the iOS platform

Comments

@erperejildo
Copy link

This was working fine before update to 8.2.5.

Screenshot 2021-11-02 at 18 29 14

I have this code showing the Retry button:

TextButton(
              onPressed: () async {
                await _checkPermission().then(
                  (hasGranted) {
                    if (hasGranted == PermissionStatus.granted) {
                      refreshContacts();
                    }
                  },
                );
              },

...

Future<PermissionStatus> _checkPermission() async {
    final Permission permission = Permission.contacts;
    final status = await permission.request();
    return status;
  }

and that always returns:
PermissionStatus.permanentlyDenied

but it doesn't open the permission question again.

Info.plist:

<key>NSContactsUsageDescription</key>
<string>This app requires access to display the contacts list. This will be used to import contacts automatically if necessary to the app contacts list.</string>

compileSdkVersion 31

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6.1 20G224 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.61.2)
[✓] Connected device (2 available)

• No issues found!
@mvanbeusekom
Copy link
Member

Hi @erperejildo,

Did you update from a version before 8.0.0 by any change? If so you will need to change the configuration in your ios/Podfile.

In versions before 8.0.0 permissions on iOS are enabled by default and you would use the configuration in the ios/Podfile to disable permissions you don't need in your App. Since version 8.0.0 we flipped the default behaviour, meaning permissions are disabled by default and you would need to configure your ios/Podfile correctly to enable the permissions you need in your App. Permissions that are not enabled explicitly will always directly return the PermissionStatus.permanentlyDenied status.

This was done because of two reasons:

  1. Protect users from listing all permissions in their ios/Runner/Info.plist and risk rejection on the Apple App Store;
  2. Ensure that we don't have to introduce a breaking change each time we introduce a new permission.

Details instructions can be found in the "iOS" section of the README.md. The change in behaviour is also mentioned in the CHANGELOG.md.

Please let me know if this is the case.

@mvanbeusekom mvanbeusekom added platform: ios Issue is related to the iOS platform status: needs more info We need more information before we can continue work on this issue. labels Nov 2, 2021
@erperejildo
Copy link
Author

@mvanbeusekom I was using ^8.1.4+2 but I can't confirm TBH if this was really working there because I updated several times til I noticed this (I already granted permissions in my phone).

In my Podfile I had this:

# 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',

        ## dart: PermissionGroup.bluetooth
        'PERMISSION_BLUETOOTH=0',
      ]

Replaced with:

# You can enable the permissions needed here. For example to enable camera
       # permission, just remove the `#` character in front so it looks like this:
       #
       # ## dart: PermissionGroup.camera
       # 'PERMISSION_CAMERA=1'
       #
       #  Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
     config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
       '$(inherited)',
       
       ## dart: PermissionGroup.calendar
       # 'PERMISSION_EVENTS=1',

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

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

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

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

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

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

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

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

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

       ## dart: PermissionGroup.sensors
       # 'PERMISSION_SENSORS=1',   

       ## dart: PermissionGroup.bluetooth
       # 'PERMISSION_BLUETOOTH=1',

       ## dart: PermissionGroup.appTrackingTransparency
       # 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

       ## dart: PermissionGroup.criticalAlerts
       # 'PERMISSION_CRITICAL_ALERTS=1'
     ]

I don't know how it was working before with 'PERMISSION_CONTACTS=0' but anyway, working now.

Thanks!

@no-response no-response bot removed the status: needs more info We need more information before we can continue work on this issue. label Nov 3, 2021
@akhiljohny
Copy link

akhiljohny commented Jul 7, 2022

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)',
##comment dart: PermissionGroup.camera
'PERMISSION_CAMERA=1'
]
end
end
end

Add this in pod file and delete pod lock and pod install then it will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: ios Issue is related to the iOS platform
Projects
None yet
Development

No branches or pull requests

3 participants