-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[image_picker] add requestFullMetadata for iOS (optional permissions) - iOS changes #5713
Changes from 2 commits
c705774
bf73c73
d48e642
3b3435f
420a4c4
ca15f9e
dff7042
b9c4cef
b3d81e3
d95b117
4a41df1
932ae7c
2424828
5685468
2464c13
9252583
09a264a
6aaa4b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ - (void)testPluginPickImageDeviceBack { | |
| camera:FLTSourceCameraRear] | ||
| maxSize:[[FLTMaxSize alloc] init] | ||
| quality:nil | ||
| fullMetadata:@(YES) | ||
| completion:^(NSString *_Nullable result, FlutterError *_Nullable error){ | ||
| }]; | ||
|
|
||
|
|
@@ -86,6 +87,7 @@ - (void)testPluginPickImageDeviceFront { | |
| camera:FLTSourceCameraFront] | ||
| maxSize:[[FLTMaxSize alloc] init] | ||
| quality:nil | ||
| fullMetadata:@(YES) | ||
| completion:^(NSString *_Nullable result, FlutterError *_Nullable error){ | ||
| }]; | ||
|
|
||
|
|
@@ -177,6 +179,27 @@ - (void)testPickMultiImageShouldUseUIImagePickerControllerOnPreiOS14 { | |
| [mockUIImagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]); | ||
| } | ||
|
|
||
| - (void)testPickImageWithoutFullMetadataPreiOS14 { | ||
| if (@available(iOS 14, *)) { | ||
| return; | ||
| } | ||
| id mockUIImagePicker = OCMClassMock([UIImagePickerController class]); | ||
| FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new]; | ||
|
||
| [plugin setImagePickerControllerOverrides:@[ mockUIImagePicker ]]; | ||
| FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"pickImage" | ||
| arguments:@{ | ||
| @"source" : @(1), | ||
| @"requestFullMetadata" : @(NO), | ||
| }]; | ||
|
|
||
| [plugin handleMethodCall:call | ||
| result:^(id _Nullable r){ | ||
| }]; | ||
|
|
||
| OCMVerify(times(1), | ||
| [mockUIImagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]); | ||
| } | ||
|
|
||
| #pragma mark - Test camera devices, no op on simulators | ||
|
|
||
| - (void)testPluginPickImageDeviceCancelClickMultipleTimes { | ||
|
|
@@ -191,6 +214,7 @@ - (void)testPluginPickImageDeviceCancelClickMultipleTimes { | |
| camera:FLTSourceCameraRear] | ||
| maxSize:[[FLTMaxSize alloc] init] | ||
| quality:nil | ||
| fullMetadata:@(YES) | ||
| completion:^(NSString *_Nullable result, FlutterError *_Nullable error){ | ||
| }]; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ dependencies: | |
| # The example app is bundled with the plugin so we use a path dependency on | ||
| # the parent directory to use the current plugin's version. | ||
| path: ../ | ||
| image_picker_platform_interface: ^2.3.0 | ||
| image_picker_platform_interface: ^2.5.0 | ||
|
||
| video_player: ^2.1.4 | ||
|
|
||
| dev_dependencies: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,7 +119,12 @@ - (void)launchPHPickerWithContext:(nonnull FLTImagePickerMethodCallContext *)con | |
| _pickerViewController.presentationController.delegate = self; | ||
| self.callContext = context; | ||
|
|
||
| [self checkPhotoAuthorizationForAccessLevel]; | ||
| BOOL requestFullMetadata = context.requestFullMetadata; | ||
|
||
| if (requestFullMetadata) { | ||
| [self checkPhotoAuthorizationForAccessLevel]; | ||
| } else { | ||
| [self showPhotoLibraryWithPHPicker:_pickerViewController]; | ||
| } | ||
| } | ||
|
|
||
| - (void)launchUIImagePickerWithSource:(nonnull FLTSourceSpecification *)source | ||
|
|
@@ -129,14 +134,24 @@ - (void)launchUIImagePickerWithSource:(nonnull FLTSourceSpecification *)source | |
| imagePickerController.delegate = self; | ||
| imagePickerController.mediaTypes = @[ (NSString *)kUTTypeImage ]; | ||
| self.callContext = context; | ||
| BOOL requestFullMetadata = context.requestFullMetadata; | ||
|
||
|
|
||
| switch (source.type) { | ||
| case FLTSourceTypeCamera: | ||
| [self checkCameraAuthorizationWithImagePicker:imagePickerController | ||
| camera:[self cameraDeviceForSource:source]]; | ||
| break; | ||
| case FLTSourceTypeGallery: | ||
| [self checkPhotoAuthorizationWithImagePicker:imagePickerController]; | ||
| if (@available(iOS 11, *)) { | ||
| if (requestFullMetadata) { | ||
| [self checkPhotoAuthorizationWithImagePicker:imagePickerController]; | ||
| } else { | ||
| [self showPhotoLibraryWithImagePicker:imagePickerController]; | ||
| } | ||
| } else { | ||
| // Prior to iOS 11, accessing gallery requires authorization | ||
| [self checkPhotoAuthorizationWithImagePicker:imagePickerController]; | ||
| } | ||
| break; | ||
| default: | ||
| [self sendCallResultWithError:[FlutterError errorWithCode:@"invalid_source" | ||
|
|
@@ -151,6 +166,7 @@ - (void)launchUIImagePickerWithSource:(nonnull FLTSourceSpecification *)source | |
| - (void)pickImageWithSource:(nonnull FLTSourceSpecification *)source | ||
| maxSize:(nonnull FLTMaxSize *)maxSize | ||
| quality:(nullable NSNumber *)imageQuality | ||
| fullMetadata:(NSNumber *)fullMetadata | ||
| completion: | ||
| (nonnull void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { | ||
| [self cancelInProgressCall]; | ||
|
|
@@ -166,6 +182,7 @@ - (void)pickImageWithSource:(nonnull FLTSourceSpecification *)source | |
| context.maxSize = maxSize; | ||
| context.imageQuality = imageQuality; | ||
| context.maxImageCount = 1; | ||
| context.requestFullMetadata = [fullMetadata boolValue]; | ||
|
|
||
| if (source.type == FLTSourceTypeGallery) { // Capture is not possible with PHPicker | ||
| if (@available(iOS 14, *)) { | ||
|
|
@@ -227,14 +244,19 @@ - (void)pickVideoWithSource:(nonnull FLTSourceSpecification *)source | |
| } | ||
|
|
||
| self.callContext = context; | ||
| BOOL requestFullMetadata = context.requestFullMetadata; | ||
|
||
|
|
||
| switch (source.type) { | ||
| case FLTSourceTypeCamera: | ||
| [self checkCameraAuthorizationWithImagePicker:imagePickerController | ||
| camera:[self cameraDeviceForSource:source]]; | ||
| break; | ||
| case FLTSourceTypeGallery: | ||
| [self checkPhotoAuthorizationWithImagePicker:imagePickerController]; | ||
| if (requestFullMetadata) { | ||
| [self checkPhotoAuthorizationWithImagePicker:imagePickerController]; | ||
| } else { | ||
| [self showPhotoLibraryWithImagePicker:imagePickerController]; | ||
| } | ||
| break; | ||
| default: | ||
| [self sendCallResultWithError:[FlutterError errorWithCode:@"invalid_source" | ||
|
|
@@ -553,8 +575,13 @@ - (void)imagePickerController:(UIImagePickerController *)picker | |
| NSNumber *maxHeight = self.callContext.maxSize.height; | ||
| NSNumber *imageQuality = self.callContext.imageQuality; | ||
| NSNumber *desiredImageQuality = [self getDesiredImageQuality:imageQuality]; | ||
| BOOL requestFullMetadata = _callContext.requestFullMetadata; | ||
|
||
|
|
||
| PHAsset *originalAsset = [FLTImagePickerPhotoAssetUtil getAssetFromImagePickerInfo:info]; | ||
| PHAsset *originalAsset; | ||
| if (requestFullMetadata) { | ||
| // Full metadata are available only in PHAsset, which requires gallery permission | ||
|
||
| originalAsset = [FLTImagePickerPhotoAssetUtil getAssetFromImagePickerInfo:info]; | ||
| } | ||
|
|
||
| if (maxWidth != nil || maxHeight != nil) { | ||
| image = [FLTImagePickerImageUtil scaledImage:image | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this test pre-14?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that it was a wrong test case, not fully covering the new flag's use case and vulnerable to false positives. I've changed it so it now verifies that there was no check for gallery authorization status.