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吧,祝你好运
如果解决了你的问题,点个赞,关注一下,或者给个大赏不为过吧!!!
如有其他问题,可留言