Flutter permission_handler 权限插件的使用详解
程序员文章站
2023-11-07 16:49:22
编译环境: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 权限插件内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
下一篇: 白了少年头竟是身体缺少这些营养素
推荐阅读