首页 > 解决方案 > 有没有办法使用颤振将相机功能修复到 iOS 上?

问题描述

问题是在 iPhone 上访问相机不起作用。尝试在 Android 上访问相机确实有效。我正在使用颤振构建应用程序,我试图使该应用程序适用于两种设备。每次我按下相机按钮。应用程序自行退出。我试图将这张图片发送到 firebase 数据库。这样做不会让我访问 iOS 的相机功能。

我试图消除照片库功能,但没有奏效。之前的相机工作。相机依赖项位于 Pubspec.yaml

Future getImage() async {
    var tempimage = await ImagePicker.pickImage(source: ImageSource.camera);
    setState(() {
      sampleimage = tempimage;

    });
  }
    Future getLibraryImage() async {
    var libraryimage = await ImagePicker.pickImage(source: ImageSource.gallery);
    setState(() {
      sampleimage = libraryimage;

    });
    }

shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9.0)),
                  onPressed: () { getImage(); },
                  child: Row(
                    children: [
                      Text(" Camera "),
                      Image.asset("images/camera.png", height: 15.0,),
                  ],
                  ),
                ),
                  ),
                ),

标签: iosflutter

解决方案


您必须向用户询问使用相机的权限。为此,您可以在Info.plist文件中添加这些行ios/Runner

<key>NSPhotoLibraryUsageDescription</key>
<string>Using the library for ...</string>
<key>NSMicrophoneUsageDescription</key>
<string>Using the mic for ...</string>
<key>NSCameraUsageDescription</key>
<string>Using the camera for ...</string>

推荐阅读