flutter ios photos permission always return permission denied permission permanently

db2dz4w8  于 2023-06-07  发布在  Flutter
关注(0)|答案(3)|浏览(835)

我正在使用flutter创建一个iOS和Android应用程序。我需要iOS和Android的photosstorage权限来访问照片以更新用户个人资料图片。我使用permission_handler包请求权限。这在Android中运行良好,但在iOS中不适用。

<key>NSPhotoLibraryUsageDescription</key>
<string>We need Photos access to allow you to update Profile Picture.</string>
var permission = Platform.isAndroid
        ? Permission.storage
        : Permission.photos;

var permissionStatus = await permission.request();

print("isGranted: " +
        permissionStatus.isGranted.toString() +
        " isDenied: " +
        permissionStatus.isDenied.toString() +
        " isLimited: " +
        permissionStatus.isLimited.toString() +
        " isRestricted: " +
        permissionStatus.isRestricted.toString() +
        " isPermanentlyDenied: " +
        permissionStatus.isPermanentlyDenied.toString());

flutter:isGranted:false被拒绝:false isLimited:false isRestricted:false是永久拒绝的:真的
我试图在模拟器(iPhone 12Pro Max)上卸载并重新安装应用程序,但仍然无法请求权限(显示请求弹出)。
我尝试了thisthisthisthis。但问题依然存在

4bbkushb

4bbkushb1#

首先将下面的代码复制并粘贴到你的podfile中。然后设置'PERMISSION_PHOTOS=1',如果你不想使用另一个权限,你可以删除或设置它=0(exp 'PERMISSION_CAMERA=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
           # e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
           config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
                '$(inherited)',
                ## dart: PermissionGroup.calendar
    
                ## dart: PermissionGroup.reminders
    
                ## dart: PermissionGroup.contacts
    
                ## 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]
    
                ## dart: PermissionGroup.notification
    
                ## dart: PermissionGroup.mediaLibrary
                'PERMISSION_MEDIA_LIBRARY=1',
                ## dart: PermissionGroup.sensors
    
                ## dart: PermissionGroup.bluetooth
    
                ## dart: PermissionGroup.appTrackingTransparency
                'PERMISSION_APP_TRACKING_TRANSPARENCY=1',
                ## dart: PermissionGroup.criticalAlerts
                'PERMISSION_SENSORS=1'
          ]
       end
   end
end

然后将其添加到info.plist文件中

<key>NSPhotoLibraryUsageDescription</key>
<string>We need Photos access to allow you to update Profile Picture.</string>

最后,在项目中使用permission_handler插件,并在需要请求权限的地方添加此代码。

var permissionStatus = await permission.request();
cbjzeqam

cbjzeqam2#

使用最新的permission_handler:包。将照片权限添加到Info.plist文件。

<!-- Permission options for the `photos` group -->
    <key>NSPhotoLibraryUsageDescription</key>
    <string>photos</string>

将以下内容添加到Podfile文件中:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    ... # Here are some configurations automatically generated by flutter

    # 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
  end
end

如果需要添加更多权限,请单击此处。删除要使用的权限前面的#字符。例如

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

在flutter中,请求var status = await Permission.photos.request(); if(status.isDenied){ //我们还没有请求权限,或者权限已经被拒绝,但不是永久性的。}
最后清洁和重建

7vux5j2d

7vux5j2d3#

权限包在iOS上的行为已更改为默认拒绝所有权限。您必须更新PList并打开希望在应用程序中使用的权限,才能使其工作。

相关问题