Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 25a585d

Browse files
authored
[image_picker] iOS: fix bug, sometimes double click cancel button will crash (#2625)
1 parent 82f8f49 commit 25a585d

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

packages/image_picker/image_picker/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.6+4
2+
3+
* Fix bug, sometimes double click cancel button will crash.
4+
15
## 0.6.6+3
26

37
* Update README

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ - (void)imagePickerController:(UIImagePickerController *)picker
326326

327327
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
328328
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];
329+
if (!self.result) {
330+
return;
331+
}
329332
self.result(nil);
330-
331333
self.result = nil;
332334
_arguments = nil;
333335
}

packages/image_picker/image_picker/ios/Tests/ImagePickerPluginTests.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@interface FLTImagePickerPlugin (Test)
1111
@property(copy, nonatomic) FlutterResult result;
1212
- (void)handleSavedPath:(NSString *)path;
13+
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
1314
@end
1415

1516
@interface ImagePickerPluginTests : XCTestCase
@@ -66,6 +67,25 @@ - (void)testPluginPickVideoDeviceBack {
6667
UIImagePickerControllerCameraDeviceRear);
6768
}
6869

70+
- (void)testPluginPickImageDeviceCancelClickMultipleTimes {
71+
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
72+
return;
73+
}
74+
FLTImagePickerPlugin *plugin =
75+
[[FLTImagePickerPlugin alloc] initWithViewController:[UIViewController new]];
76+
FlutterMethodCall *call =
77+
[FlutterMethodCall methodCallWithMethodName:@"pickImage"
78+
arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}];
79+
[plugin handleMethodCall:call
80+
result:^(id _Nullable r){
81+
}];
82+
plugin.result = ^(id result) {
83+
84+
};
85+
[plugin imagePickerControllerDidCancel:[plugin getImagePickerController]];
86+
[plugin imagePickerControllerDidCancel:[plugin getImagePickerController]];
87+
}
88+
6989
- (void)testPluginPickVideoDeviceFront {
7090
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
7191
return;

packages/image_picker/image_picker/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: image_picker
22
description: Flutter plugin for selecting images from the Android and iOS image
33
library, and taking new pictures with the camera.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker
5-
version: 0.6.6+3
5+
version: 0.6.6+4
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)