颤振权限处理程序授予未在 iOS 上显示

时间:2021-07-31 06:36:43

标签: flutter dart

我创建了一个类,在它登录后立即请求许可,它显示在 Android 上,但在 iOs 上我没有看到任何权限授予。

class PermissionService {
  Future permissionHandler() async {
    await Permission.contacts.shouldShowRequestRationale;
    if (await Permission.contacts.request().isGranted) {
      // Either the permission was already granted before or the user just granted it.
    }
    Map<Permission, PermissionStatus> statuses = await [
      Permission.locationWhenInUse,
      Permission.locationAlways,
      Permission.photos,
      Permission.camera,
      Permission.location,
      Permission.microphone,
      Permission.notification,
    ].request();

    if (statuses[Permission.location].isDenied) {
      print("Location permission is denied.");
    }

    if (statuses[Permission.camera].isDenied) {
      print("Camera permission is denied.");
    }
    if (statuses[Permission.photos].isDenied) {
      print("Photos permission is denied.");
    }
    if (statuses[Permission.notification].isDenied) {
      print("Notification permission is denied.");
    }
    if (statuses[Permission.microphone].isDenied) {
      print("Microphone permission is denied.");
    }
    if (statuses[Permission.locationWhenInUse].isDenied) {
      print("locationWhenInUse permission is denied.");
    }
    if (statuses[Permission.locationAlways].isDenied) {
      print("locationAlways permission is denied.");
    }
  }
}

我在 Login.dart 的初始化状态中调用这个函数

1 个答案:

答案 0 :(得分:0)

permission_handler 包在版本 8.0.0 中引入了重大更改,请参阅 changelog。默认情况下,iOS 上的权限是禁用的,并且您在 Podfile 中设置了正确的 GCC_PREPROCESSOR_DEFINITIONS。并且示例 Podfile 可以在 here 中找到,但基本上您必须将其添加到您的 Podfile 中,将您不使用的权限设置为 0

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/master/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=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',
      ]
    end
  end
end