target.build_configurations.each do |config| # Here are some configurations automatically generated by flutter
# 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/ios/Classes/PermissionHandlerEnums.h config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ '$(inherited)',
end #########################################################################
end end
在需要的权限前去掉注释
ios/Runner/Info.plist
1 2 3 4 5 6
<key>NSCameraUsageDescription</key> <string>Need to access the camera to take photos and videos to share with friends.</string> <key>NSMicrophoneUsageDescription</key> <string>Requires access to the microphone to shoot video and voice to share with friends.</string> <key>NSPhotoLibraryUsageDescription</key> <string>Requires access to the photo library to read videos and photos to share with friends.</string>
<!-- Internet permissions do not affect the `permission_handler` plugin, but are requiredif your app needs access to the internet. --> <uses-permission android:name="android.permission.INTERNET"/>
<!-- Permissions options for the `storage` group --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Permissions options for the `camera` group --> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<!-- Permissions options for the `microphone` or `speech` group --> <uses-permission android:name="android.permission.RECORD_AUDIO" /> </manifest>
/// 动态授权 classPrivilege{ /// 是否有相册权限 static Future<PrivilegeStatus> photos() async { var value = false; if (GetPlatform.isIOS) { var statuses = await [Permission.photos].request(); value = statuses[Permission.photos] == PermissionStatus.granted; } if (GetPlatform.isAndroid) { var statuses = await [Permission.storage].request(); value = statuses[Permission.storage] == PermissionStatus.granted; } return PrivilegeStatus( result: value, message: value ? 'ok' : 'Please open photo gallery access', ); }
/// 是否有相机权限 static Future<PrivilegeStatus> camera() async { var value = false; var permissions = <Permission>[]; permissions.addAll([Permission.camera, Permission.microphone]); if (GetPlatform.isIOS) { permissions.add(Permission.photos); } if (GetPlatform.isAndroid) { permissions.add(Permission.storage); } var statuses = await permissions.request(); value = statuses[Permission.camera] == PermissionStatus.granted && statuses[Permission.microphone] == PermissionStatus.granted; if (GetPlatform.isIOS) { value = statuses[Permission.photos] == PermissionStatus.granted; } if (GetPlatform.isAndroid) { value = statuses[Permission.storage] == PermissionStatus.granted; } return PrivilegeStatus( result: value, message: value ? 'ok' : 'Please turn on camera and microphone access', ); }
/// 是否有麦克风权限 static Future<PrivilegeStatus> microphone() async { var value = false; var statuses = await [Permission.microphone].request(); value = statuses[Permission.microphone] == PermissionStatus.granted; return PrivilegeStatus( result: value, message: value ? 'ok' : 'Please turn on microphone access', ); }
/// 是否有存储权限 static Future<bool> storage() async { bool value = false; String text = ''; if (GetPlatform.isAndroid) { value = await Permission.storage.request().isGranted; text = 'Please allow access to storage space, settings will be opened soon'; } if (GetPlatform.isIOS) value = true; if (!value) { Loading.toast(text); await Future.delayed(constDuration(seconds: 2)); openSettings(); } return value; }