Flutter permission_handler 許可權外掛的使用詳解
阿新 • • 發佈:2020-04-14
編譯環境: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 許可權外掛內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!