[英]Flutter: 'Lost connection to device.' second time using image_picker to select photo from gallery on iOS
[英]While picking an image from gallery, image_picker is crashing the the app on IOS with no logs in the console
每當我使用 image_picker: ^0.8.6+1 插件單擊從圖庫中選擇圖像時,它都會打開圖庫,當我輸入 select 任何圖像時,應用程序就會崩潰,並在控制台中顯示以下消息: “與設備失去連接。”
這是 Runner 停止時我得到的報告。
Last Exception Backtrace:
0 CoreFoundation 0x7ff80042889b __exceptionPreprocess + 226
1 libobjc.A.dylib 0x7ff80004dba3 objc_exception_throw + 48
2 CoreFoundation 0x7ff800437ab8 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x7ff80042cd71 ___forwarding___ + 1431
4 CoreFoundation 0x7ff80042f068 _CF_forwarding_prep_0 + 120
5 image_picker_ios 0x109b6d5de +[FLTImagePickerMetaDataUtil convertImage:usingType:quality:] + 238 (FLTImagePickerMetaDataUtil.m:86)
6 image_picker_ios 0x109b6df9a +[FLTImagePickerPhotoAssetUtil saveImageWithMetaData:image:suffix:type:imageQuality:] + 170 (FLTImagePickerPhotoAssetUtil.m:88)
7 image_picker_ios 0x109b6dc16 +[FLTImagePickerPhotoAssetUtil saveImageWithOriginalImageData:image:maxWidth:maxHeight:imageQuality:] + 566 (FLTImagePickerPhotoAssetUtil.m:57)
8 image_picker_ios 0x109b749e5 __52-[FLTPHPickerSaveImageToPathOperation processImage:]_block_invoke + 261 (FLTPHPickerSaveImageToPathOperation.m:143)
9 image_picker_ios 0x109b74af2 __52-[FLTPHPickerSaveImageToPathOperation processImage:]_block_invoke.73 + 130 (FLTPHPickerSaveImageToPathOperation.m:160)
10 Photos 0x7ff80bb5f7a0 __79-[PHImageManager requestImageDataAndOrientationForAsset:options:resultHandler:]_block_invoke_2 + 150
11 libdispatch.dylib 0x7ff80013b7fb _dispatch_call_block_and_release + 12
12 libdispatch.dylib 0x7ff80013ca3a _dispatch_client_callout + 8
13 libdispatch.dylib 0x7ff80014c32c _dispatch_main_queue_drain + 1338
14 libdispatch.dylib 0x7ff80014bde4 _dispatch_main_queue_callback_4CF + 31
15 CoreFoundation 0x7ff800387b1f __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
16 CoreFoundation 0x7ff800382436 __CFRunLoopRun + 2482
17 CoreFoundation 0x7ff8003816a7 CFRunLoopRunSpecific + 560
18 GraphicsServices 0x7ff809cb128a GSEventRunModal + 139
19 UIKitCore 0x11fa14ad3 -[UIApplication _run] + 994
20 UIKitCore 0x11fa199ef UIApplicationMain + 123
21 Runner 0x102d7c24f main + 63 (AppDelegate.swift:13)
22 dyld_sim 0x1090b42bf start_sim + 10
23 dyld 0x108fff52e start + 462
這是我的 flutter 醫生
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.6.2 21G320 darwin-x64, locale en-PK)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.74.3)
[✓] Connected device (4 available)
[✓] HTTP Host Availability
這是我在 pubspec 文件中使用的插件和 dart SDK
environment:
sdk: ">=2.12.0 <3.0.0"
image_picker: ^0.8.6+1
google_maps_flutter: ^2.2.3
這是代碼示例:
try {
final ImagePicker picker = ImagePicker();
final image = await picker.pickImage(source: source, imageQuality: 30, maxHeight: 400, maxWidth: 300);
if (image != null) {
final cropped = await ImageCropper().cropImage(
sourcePath: image.path,
aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
compressQuality: 100,
cropStyle: CropStyle.circle,
maxHeight: 700,
maxWidth: 700,
);
if (cropped != null) {
setState(() {
_selectedFile = File(cropped.path);
});
}
} else {
setState(() {});
}
} catch(e) {
debugPrint('Error in image picker: $e');
}
這是 info.plist 文件中的權限聲明
<key>NSCameraUsageDescription</key>
<string>abcAPP needs to access your camera only for scanning the Document and setting-up your Profile.</string>
<key>NSLocationUsageDescription</key>
<string>abcAPP needs to access your location to help you while finding your rides nearby you.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>abcAPP needs to access your location to help you while finding your rides nearby you.</string>
<key>NSMicrophoneUsageDescription</key>
<string>abcAPP needs to access your Microphone for recording the video.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>abcAPP needs to access your Photo Library to set-up your Profile.</string>
所有權限都正常工作,在授予權限后,圖庫打開並從圖庫中選擇任何圖像會使應用程序崩潰,Android 工作室控制台中沒有日志。
我已經在模擬器和真實設備上測試了這段代碼,但沒有成功。 相同的代碼在 Android 端工作正常,但不知道為什么幾周前它工作正常而現在不工作。
經過兩天的努力,我知道這個問題在這個 image_picker_ios: ^0.8.6+6 版本中得到了解決。 但不知為何主“image_picker: ^0.8.6+1”中沒有加入這個版本。 這就是為什么我像這樣在 dependency_overrides 下覆蓋 pubspec.yaml 文件中的特定 package 的原因。
dependency_overrides:
image_picker_ios: ^0.8.6+6
現在它就像一個魅力:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.