Flutter-权限permission_handler插件配置

一、Android端:

1、确保gradle.properties文件有以下配置

ini 复制代码
android.useAndroidX=true
android.enableJetifier=true

2、确保android/app/build.gradle的 compileSdkVersion到31

二、iOS端:

1、Podfile文件配置

ruby 复制代码
# 权限配置开始
  config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
      '$(inherited)',

      ## 仅允许写入日历的权限(iOS 16 及以下)
      # 'PERMISSION_EVENTS=1',

      ## 允许完全访问日历的权限(iOS 17及以上)
      # 'PERMISSION_EVENTS_FULL_ACCESS=1',

      ## 提醒事项权限
      # 'PERMISSION_REMINDERS=1',

      ## 联系人权限
      # 'PERMISSION_CONTACTS=1',

      ## 相机权限
      # 'PERMISSION_CAMERA=1',

      ## 麦克风权限
      # 'PERMISSION_MICROPHONE=1',

      ## 语音识别权限
      # 'PERMISSION_SPEECH_RECOGNIZER=1',

      ## 照片权限
      # 'PERMISSION_PHOTOS=1',

      ## 位置权限组(包括始终、使用中)
      # 'PERMISSION_LOCATION=1',

      ## 通知权限
      # 'PERMISSION_NOTIFICATIONS=1',

      ## 媒体库权限
      # 'PERMISSION_MEDIA_LIBRARY=1',

      ## 传感器权限
      # 'PERMISSION_SENSORS=1',

      ## 蓝牙权限
      # 'PERMISSION_BLUETOOTH=1',

      ## 应用跟踪透明度权限
      # 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

      ## 关键警报权限
      # 'PERMISSION_CRITICAL_ALERTS=1'
    ]
    # 权限配置结束
  end

2、Info.plist里的权限要正常添加

  • 日历权限(< iOS 17) NSCalendarsUsageDescription PERMISSION_EVENTS
  • 日历写权限(iOS 17+) NSCalendarsWriteOnlyAccessUsageDescription PERMISSION_EVENTS
  • 日历完全访问权限(iOS 17+) NSCalendarsFullAccessUsageDescription PERMISSION_EVENTS_FULL_ACCESS
  • 提醒事项权限 NSRemindersUsageDescription PERMISSION_REMINDERS
  • 联系人权限 NSContactsUsageDescription PERMISSION_CONTACTS
  • 相机权限 NSCameraUsageDescription PERMISSION_CAMERA
  • 相册权限 NSPhotoLibraryAddUsageDescription -
  • 麦克风权限 NSMicrophoneUsageDescription PERMISSION_MICROPHONE
  • 语音识别权限 NSSpeechRecognitionUsageDescription PERMISSION_SPEECH_RECOGNIZER
  • 照片权限 NSPhotoLibraryUsageDescription PERMISSION_PHOTOS
  • 位置权限 NSLocationUsageDescription, PERMISSION_LOCATION
  • 始终使用位置权限 NSLocationAlwaysAndWhenInUseUsageDescription PERMISSION_NOTIFICATIONS
  • 仅在使用时使用位置权限 NSLocationWhenInUseUsageDescription PERMISSION_NOTIFICATIONS
  • 通知权限 PermissionGroupNotification PERMISSION_NOTIFICATIONS

三、PermissionStatus类型介绍

arduino 复制代码
enum PermissionStatus {
  /// The user denied access to the requested feature.
  denied, //权限被拒绝
 
  /// The user granted access to the requested feature.
  granted, //通过
 
  /// The OS denied access to the requested feature. The user cannot change
  /// this app's status, possibly due to active restrictions such as parental
  /// controls being in place.
  /// *Only supported on iOS.*
  restricted, //IOS
 
  ///User has authorized this application for limited access.
  /// *Only supported on iOS (iOS14+).*
  limited, //IOS
 
  /// The user denied access to the requested feature and selected to never
  /// again show a request for this permission. The user may still change the
  /// permission status in the settings.
  /// *Only supported on Android.*
  permanentlyDenied, //拒绝,且不在提示
}
相关推荐
张风捷特烈4 小时前
Flutter 伪3D绘制#03 | 轴测投影原理分析
android·flutter·canvas
马拉萨的春天7 小时前
flutter 项目结构目录以及pubspec.ymal等文件描述
flutter
bst@微胖子1 天前
Flutter项目之登录注册功能实现
开发语言·javascript·flutter
小墙程序员1 天前
Flutter 教程(十一)多语言支持
flutter
无知的前端1 天前
Flutter 一文精通Isolate,使用场景以及示例
android·flutter·性能优化
yidahis1 天前
Flutter 运行新建项目也报错?
flutter·trae
江上清风山间明月1 天前
一周掌握Flutter开发--9. 与原生交互(下)
flutter·交互·原生·methodchannel
GeniuswongAir1 天前
Flutter极速接入IM聊天功能并支持鸿蒙
flutter·华为·harmonyos
sayen1 天前
记录 flutter 文本内容展示过长优化
前端·flutter