简体   繁体   English

Flutter Image_Picker 在打开相机时崩溃 iOS 应用程序

[英]Flutter Image_Picker crash iOS app when open Camera

everything works perfect in Android when I open gallery or Camera, but when I try on iOS (emulator and real device) gallery works perfect but as soon as I press the Camera option the app crash without console logs only "Lost connection to device"当我打开图库或相机时,一切在 Android 中运行完美,但当我尝试 iOS(模拟器和真实设备)时,图库运行完美,但一旦我按下相机选项,应用程序崩溃而没有控制台日志,只有“与设备的连接丢失”

 // get image File camera
 _getFromCamera(BuildContext context) async {
   XFile? pickedFile = await ImagePicker().pickImage(
     source: ImageSource.camera,
     maxWidth: 1800,
     maxHeight: 1800,
   );
   File rotatedImage =
       await FlutterExifRotation.rotateAndSaveImage(path: pickedFile!.path);
   if (pickedFile != null) {
     image = rotatedImage;
     //File(pickedFile.path);
     final userId = widget.id;
     widget.bloc.uploadProfilePicture(image, userId);
   }
 }

Then I called the function in a Icon button

TextButton.icon(
                     icon: Icon(
                       Icons.photo_camera,
                       color: Theme.of(context).primaryColor,
                     ),
                     label: Text(
                       AppLocalization.of(context)!
                           .getTranslatedValues("cameraLbl")!,
                       style: TextStyle(
                           color: Theme.of(context).colorScheme.secondary,
                           fontWeight: FontWeight.bold),
                     ),
                     onPressed: () {
                       _getFromCamera(context);
                       Navigator.of(context).pop();
                     },
                   )

You have to add additional permissions inside the info.plist file您必须在 info.plist 文件中添加额外的权限

Add these entries inside it:在其中添加这些条目:

<key>NSPhotoLibraryUsageDescription</key>
<string>Needs PhotoLib access</string>

<key>NSCameraUsageDescription</key>
<string>Needs camera access</string>

To add permissions in flutter application, you need to add permissions in both android manifest and info.plist file.要在 flutter 应用程序中添加权限,您需要在 android 清单和 info.plist 文件中添加权限。

Also you can use any string inside the string tag, and that string would be shown to the user as why the user needs to give permission.您也可以在字符串标签内使用任何字符串,该字符串将作为用户需要授予权限的原因显示给用户。

Add the permisson keys inside the info.plist file (located in {app_folder}/ios/Runner/Info.plist在 info.plist 文件中添加权限密钥(位于 {app_folder}/ios/Runner/Info.plist

Here is the info.plist file located这是位于 info.plist 文件

and add并添加

<key>NSPhotoLibraryUsageDescription</key>
<string>Needs PhotoLib access</string>

<key>NSCameraUsageDescription</key>
<string>Needs camera access</string>

this will display the permission window for the camera and gallery这将显示相机和图库的权限 window

Hint: Hot reload is not enougth!提示:热重载是不够的! Press "Stop Debugging" and "Start Debugging"按“停止调试”和“开始调试”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter IOS 应用程序不会以 image_picker 启动:^0.6.3+4 - Flutter IOS app won't start with image_picker: ^0.6.3+4 颤振:“与设备的连接丢失。” 第二次使用 image_picker 从 iOS 上的图库中选择照片 - Flutter: 'Lost connection to device.' second time using image_picker to select photo from gallery on iOS Flutter image_picker 视频库 OSError: Operation not allowed [Errno 1] IOS 13 - Flutter image_picker video gallery OSError: Operation not permitted [Errno 1] IOS 13 从图库中选择图像时,image_picker 使应用程序崩溃 IOS,控制台中没有任何日志 - While picking an image from gallery, image_picker is crashing the the app on IOS with no logs in the console image_picker:如果首先访问相机,则取消按钮在图库中不可见 - image_picker: Cancel button not visible in gallery, if camera was accessed first 有没有办法使用 Image_Picker 或来自 pub.dev 的类似插件从 Flutter 中的 ios 设备中选择 *.HEIC 文件? - Is there a way to pick *.HEIC files from an ios device in Flutter using Image_Picker or similar plugins from pub.dev? 我正在使用图像选择器在 flutter 中打开相机和 select 图像,它对 android 设备非常有效,但在 ZBA3F2ADEA47B86B0DCZED3 - I am using image picker to open camera and select images in flutter and it works perfectly fine for android devices but in IOS it won't work Flutter multi_image_picker 相机选项未在 iOS 中显示。 当我已经启用相机并在 info.plist 中写入权限时 - Flutter multi_image_picker camera option not showing in iOS. When i already enable camera and write the the permission in info.plist Flutter 图像选择器卡在相机上 - Flutter Image Picker Stuck On Camera Flutter IoS 提交到appStore时应用崩溃 - Flutter IoS App crash when submitted to appStore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM