Flutter permission_handler 权限插件的使用详解
程序员文章站
2022-06-11 11:49:50
编译环境:flutter 版本v1.12.hotfix9 dart sdk:2.7.21 pubspec.yaml中引入: # 权限 permission_handler: ^3.2.0ios中inf...
编译环境: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?</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 权限插件的使用的文章就介绍到这了,更多相关flutter permission_handler 权限插件内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
推荐阅读
-
Eclipse中php插件安装及Xdebug配置的使用详解
-
Kotlin之在Gradle中无参(no-arg)编译器插件的使用详解
-
Flutter permission_handler 权限插件的使用详解
-
详解jQuery uploadify文件上传插件的使用方法
-
Linux chmod命令详解和使用实例(改变文件或目录的访问权限)
-
vue.js国际化 vue-i18n插件的使用详解
-
魔方Newlife.Cube权限系统的使用及模版覆盖详解
-
关于flutter插件地图的使用flutter_map
-
bootstrap table插件的分页与checkbox使用详解
-
Flutter中mixin的使用详解