dart 使用permission_handler包时,Flutter IOS未显示位置权限对话框

9udxz4iz  于 2023-03-15  发布在  Flutter
关注(0)|答案(2)|浏览(252)

我如何修复我的flutter ios应用程序没有显示权限对话框我目前使用permission_handler 10.0.0软件包,该软件包在android上运行良好,但在ios上,授予或拒绝权限的对话框根本不会弹出。

chkPermissionLoc(ctx) async {
var perLocation = await Permission.location.status;
    if (perLocation.isDenied) {
        await [Permission.location].request();//This isn't running
        print('Permission is Denied');
    } else if (perLocation.isGranted) {
      print('Permission is Granted');
    } else if (perLocation.isPermanentlyDenied) {
      print('Permission is permanently denied');
    } else if (perLocation.isRestricted) {
      print('Permission is OS restricted');
    } else if (perLocation.isLimited) {
      print('Permission is Limited');
    }
}

应用程序只是打印了Permission is Denied,但是它之前的函数根本没有被调用,该函数应该显示对话框。我已经按照软件包中的文档在info.plist文件中添加了字符串值,但仍然是同一个问题。

<key>NSLocationWhenInUseUsageDescription</key>
    <string>Permission is Needed</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Permission is Needed 2</string>
    <key>NSLocationUsageDescription</key>
    <string>Permission is Needed 3</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Permission is Needed 4</string>

任何帮助都将不胜感激

xwmevbvl

xwmevbvl1#

请按照以下步骤更新播客文件。
1.进入ios文件夹
1.删除Podfile.lock文件

  1. rm-rf吸引舱
  2. Pod缓存清除--全部
    1.荚解体
  3. pod设置
  4. pod安装
    pod存储库更新
    希望能有所帮助
oyjwcjzk

oyjwcjzk2#

你需要添加一些代码到你的播客文件中,你可以参考flutter_permission handler in iOS。只是简单地从官方文档中复制代码,无论你需要什么权限,只要取消注解即可。
'安装后执行|安装程序|安装程序。pod_项目。目标。每个do|靶|

# Start of the permission_handler configuration
target.build_configurations.each do |config|

  # 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_apple/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'
  ]

end 
# End of the permission_handler configuration

末端

相关问题