flutter权限设置报错

6 篇文章 1 订阅
5 篇文章 0 订阅

flutter权限问题

 /Users/qingzhou/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:40:81: error: use of undeclared identifier 'PHAccessLevelAddOnly'
            [PHPhotoLibrary requestAuthorizationForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus authorizationStatus) {
                                                                                    ^
    /Users/qingzhou/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:40:102: error: use of undeclared identifier 'PHAccessLevelReadWrite'
            [PHPhotoLibrary requestAuthorizationForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus authorizationStatus) {
                                                                                                         ^
    /Users/qingzhou/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:53:89: error: use of undeclared identifier 'PHAccessLevelAddOnly'
            status = [PHPhotoLibrary authorizationStatusForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite];
                                                                                            ^
    /Users/qingzhou/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:53:110: error: use of undeclared identifier 'PHAccessLevelReadWrite'
            status = [PHPhotoLibrary authorizationStatusForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite];
                                                                                                                 ^
    /Users/qingzhou/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:71:14: error: use of undeclared identifier 'PHAuthorizationStatusLimited'; did you mean 'PHAuthorizationStatusDenied'?
            case PHAuthorizationStatusLimited:
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                 PHAuthorizationStatusDenied
    In module 'Photos' imported from /Users/fanqingzhong/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.h:11:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/Photos.framework/Headers/PHPhotoLibrary.h:22:5: note: 'PHAuthorizationStatusDenied' declared here
        PHAuthorizationStatusDenied,            // User has explicitly denied this application access to photos data.
        ^
    /Users/qingzhou/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:71:14: error: duplicate case value 'PHAuthorizationStatusDenied'
            case PHAuthorizationStatusLimited:
                 ^
    /Users/qingzhou/flutter-2/.pub-cache/hosted/pub.flutter-io.cn/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:67:14: note: previous case defined here
            case PHAuthorizationStatusDenied:

看到这么一大堆问题你一定很头大吧,不要担心,只需修改几个地方就可以完美解决问题:
找到你的podfile文件,如图:
在这里插入图片描述
在该文件下添加这些东西就可以保证你的程序不报错了!

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/develop/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=0',

        ## dart: PermissionGroup.reminders
         'PERMISSION_REMINDERS=0',

        ## dart: PermissionGroup.contacts
         'PERMISSION_CONTACTS=0',

        ## dart: PermissionGroup.camera
         'PERMISSION_CAMERA=0',

        ## dart: PermissionGroup.microphone
         'PERMISSION_MICROPHONE=0',

        ## dart: PermissionGroup.speech
        'PERMISSION_SPEECH_RECOGNIZER=0',

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

        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
         'PERMISSION_LOCATION=0',
       
        ## dart: PermissionGroup.notification
         'PERMISSION_NOTIFICATIONS=0',

        ## dart: PermissionGroup.mediaLibrary
         'PERMISSION_MEDIA_LIBRARY=0',

        ## dart: PermissionGroup.sensors
         'PERMISSION_SENSORS=0'
      ]

    end
  end
end

在适当位置添加代码哦,将中间那些补上就可以了,然后在你的info.plist文件添加上你的权限,大功告成.
注意注释部分:(自己去翻译一下吧!很重要哦)
在这里插入图片描述

至于权限:

<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>

按需添加!

如果你把上面的都操作完了,发现还是不能解决问题,那么查看下你Podfile.lock中
在这里插入图片描述

如果是5.1.0+2,那你就切换成5.0.1吧,祝你好运
如果解决了你的问题,点个赞,关注一下,或者给个大赏不为过吧!!!
如有其他问题,可留言

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~轻舟~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值