如何在Flutter项目中添加相机权限?

5
我希望通过点击一个按钮打开相机,但是在iOS包中无法添加相机和相册权限。
我有这些密钥:
NSPhotoLibraryUsageDescription
NSCameraUsageDescription
NSMicrophoneUsageDescription

我不知道应该把这些代码放在哪里。


我的回答有帮助吗? - tomerpacific
5个回答

14

编辑这个文件:

[Flutter Project Folder]/ios/Runner/Info.plist

添加这些条目:

<key>NSPhotoLibraryUsageDescription</key>
<string>App needs access to photo lib for profile images</string>

<key>NSCameraUsageDescription</key>
<string>To capture profile photo please grant camera access</string>

字符串部分可以是任何你想让用户看到的描述,作为解释为什么你的应用程序需要这些权限。

这些行应该添加在<uses-permission>标签之后。

其他选项有很好的阐述,可参考此处: https://dev59.com/YlkS5IYBdhLWcg3wu4vL#39519960


2
为了在Flutter中添加权限,你需要在AndroidManifest.xml文件和info.plist文件中都添加权限。
要将你所需的特定权限添加到info.plist中,可以前往:

iOS -> Runner -> info.plist

enter image description here


1

0
你应该尝试通过更新Podfile来解决问题。
你可以点击这个链接进行操作。
通过这种方式,你可以设置默认权限,并在权限对话框中更新权限。

虽然这个链接可能回答了问题,但最好在这里包含答案的关键部分,并提供链接作为参考。仅有链接的答案如果链接页面发生变化,可能会变得无效。- 来自审核 - undefined

-1

需要向 ios/Runner/info.plist 文件中的 UILaunchStoryboardName 键之前添加有关图库、相机和麦克风的权限。

<dict>
    <!-- permissions -->
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Please grant photo gallery access</string>
    <key>NSCameraUsageDescription</key>
    <string>Please grant camera access</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>Please grant microphone access</string>
    <!-- end permissions -->
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
</dict>

请注意,plist文件是以制表符分隔的,因此不应使用空格。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接