Flutterpermission_handler权限插件的使⽤详解编译环境:Flutter 版本v1.12.hotfix9 dart SDK:2.7.2
1 pubspec.yaml中引⼊:
#  权限
permission_handler: ^3.2.0
ios中info.plist配置(根据权限情况使⽤):
<!-- Permission options for the `location` group -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location when in use</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Always and when in use!</string>
flutter sdk<key>NSLocationUsageDescription</key>
<string>Older devices need location.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Can I haz location always?</string>
<!-- Permission options for the `mediaLibrary` group -->
<key>NSAppleMusicUsageDescription</key>
<string>Music!</string>
<key>kTCCServiceMediaLibrary</key>
<string>media</string>
<!-- Permission options for the `calendar` group -->
<key>NSCalendarsUsageDescription</key>
<string>Calendars</string>
<!-- Permission options for the `camera` group -->
<key>NSCameraUsageDescription</key>
<string>camera</string>
<!-- Permission options for the `contacts` group -->
<key>NSContactsUsageDescription</key>
<string>contacts</string>
<!-- Permission options for the `microphone` group -->
<key>NSMicrophoneUsageDescription</key>
<string>microphone</string>
<!-- Permission options for the `speech` group -->
<key>NSSpeechRecognitionUsageDescription</key>
<string>speech</string>
<!-- Permission options for the `sensors` group -->
<key>NSMotionUsageDescription</key>
<string>motion</string>
<!-- Permission options for the `photos` group -->
<key>NSPhotoLibraryUsageDescription</key>
<string>photos</string>
<!-- Permission options for the `reminder` group -->
<key>NSRemindersUsageDescription</key>
<string>reminders</string>
2 代码中具体使⽤:
void chosePhoto(int index) async {
PermissionHandler().requestPermissions(
[PermissionGroup.photos, PermissionGroup.camera]).then((map) {
if (map[PermissionGroup.photos] == anted ||
map[PermissionGroup.camera] == anted) {
chosePhotoFromPhone(context, index);
}
});
}
3 总结:
在使⽤的过程中可能会出现androidX 或者Swift语⾔的适配,这时候需要根据具体情况进⾏修改。
到此这篇关于Flutter permission_handler 权限插件的使⽤的⽂章就介绍到这了,更多相关Flutter permission_handler 权限插件内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。