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

[image_picker] Fix pickMultiImage throwing an error on iOS 13 and below. #5264

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.4+12

* Fixes `pickMultiImage` throwing an exception on iOS 13 and below.

## 0.8.4+11

* Splits from `image_picker` as a federated implementation.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ - (void)testPickMultiImageShouldUseUIImagePickerControllerOnPreiOS14 {

OCMVerify(times(1),
[mockUIImagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]);
XCTAssertEqual([plugin getMaxImagesAllowed], 0);
}

#pragma mark - Test camera devices, no op on simulators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
[registrar addMethodCallDelegate:instance channel:channel];
}

- (int)getMaxImagesAllowed {
return self.maxImagesAllowed;
}

- (UIImagePickerController *)createImagePickerController {
if ([self.imagePickerControllerOverrides count] > 0) {
UIImagePickerController *controller = [self.imagePickerControllerOverrides firstObject];
Expand Down Expand Up @@ -136,13 +140,16 @@ - (void)pickImageWithPHPicker:(int)maxImagesAllowed API_AVAILABLE(ios(14)) {
[self checkPhotoAuthorizationForAccessLevel];
}

- (void)launchUIImagePickerWithSource:(int)imageSource {
- (void)launchUIImagePickerWithSource:(int)imageSource multiImage:(BOOL)multiImage {
UIImagePickerController *imagePickerController = [self createImagePickerController];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.delegate = self;
imagePickerController.mediaTypes = @[ (NSString *)kUTTypeImage ];

self.maxImagesAllowed = 1;
// Picking multiple images is unsupported on iOS 13 and below,
// but this still has to be set as it determines the correct
// return type (list or single item).
self.maxImagesAllowed = multiImage ? 0 : 1;

switch (imageSource) {
case SOURCE_CAMERA:
Expand Down Expand Up @@ -179,16 +186,16 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[self pickImageWithPHPicker:1];
} else {
// UIImagePicker is used
[self launchUIImagePickerWithSource:imageSource];
[self launchUIImagePickerWithSource:imageSource multiImage:false];
}
} else {
[self launchUIImagePickerWithSource:imageSource];
[self launchUIImagePickerWithSource:imageSource multiImage:false];
}
} else if ([@"pickMultiImage" isEqualToString:call.method]) {
if (@available(iOS 14, *)) {
[self pickImageWithPHPicker:0];
} else {
[self launchUIImagePickerWithSource:SOURCE_GALLERY];
[self launchUIImagePickerWithSource:SOURCE_GALLERY multiImage:true];
}
} else if ([@"pickVideo" isEqualToString:call.method]) {
UIImagePickerController *imagePickerController = [self createImagePickerController];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
- (void)handleSavedPathList:(NSArray *)pathList;

/** The property to keep track of how many images are allowed to be picked */
- (int)getMaxImagesAllowed;

/**
* Tells the delegate that the user cancelled the pick operation.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker_ios
description: iOS implementation of the video_picker plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.4+11
version: 0.8.4+12

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down