美文网首页Flutter学习
flutter Permission权限请求iOS不弹窗

flutter Permission权限请求iOS不弹窗

作者: Superman168 | 来源:发表于2023-03-19 13:39 被阅读0次

问题

前两天,重新pod 之后,Permission 请求权限的时候,不弹窗,无法获取权限,拍照等无法使用。

解决方法

网上说修改
android/gradle.properties中的
android.enableR8=true

android.enableR8=false
再次打包后就可以了!
这是安卓的配置,跟iOS无关。

我看了,项目中设置的是android.enableR8=true,但是没有修改代码,使用的还是之前的请求权限的方法:

/// 请求基本权限
  requestAllPermission() async {
    //请求权限
   Map<Permission, PermissionStatus> statuses = await [
     Permission.camera,
     Permission.storage,
     Permission.photos,
   ].request();
   //校验权限
   if(statuses[Permission.camera] != PermissionStatus.granted){
     LogsUtil.e("无照相权限");
   }
   if(statuses[Permission.storage] != PermissionStatus.granted){
     LogsUtil.e("无存储权限");
   }

  }

分析是外部环境的问题,找了之前的记录,发现了Profile文件中少了配置,删了之前的,自动生成的,少了配置,需要添加以下的配置:

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['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
      # 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
end

需要什么权限就打开什么权限,然后重新pod就没问题了,记录一下,踩坑里程。

相关文章

网友评论

    本文标题:flutter Permission权限请求iOS不弹窗

    本文链接:https://www.haomeiwen.com/subject/trgaldtx.html