温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用Flutter permission_handler权限插件

发布时间:2020-08-04 10:25:01 来源:亿速云 阅读:660 作者:小猪 栏目:移动开发

这篇文章主要为大家展示了如何使用Flutter permission_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>
 <key>NSLocationUsageDescription</key>
 <string>Older devices need location.</string>
 <key>NSLocationAlwaysUsageDescription</key>
 <string>Can I haz location always&#63;</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] == PermissionStatus.granted ||
  map[PermissionGroup.camera] == PermissionStatus.granted) {
 chosePhotoFromPhone(context, index);
 }
 });
 }

3 总结:

在使用的过程中可能会出现androidX 或者Swift语言的适配,这时候需要根据具体情况进行修改。

以上就是关于如何使用Flutter permission_handler权限插件的内容,如果你们有学习到知识或者技能,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI