From 6d50058bf73b870fda979fa7965b664c2f0a2989 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Wed, 14 Dec 2022 15:21:03 -0600 Subject: [PATCH 1/3] fix check for authorization status --- .../image_picker_ios/ios/Classes/FLTImagePickerPlugin.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m index 27b06ba994ef..838fca26d901 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m @@ -368,11 +368,13 @@ - (void)checkPhotoAuthorizationWithImagePicker:(UIImagePickerController *)imageP } - (void)checkPhotoAuthorizationForAccessLevel API_AVAILABLE(ios(14)) { - PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; + PHAccessLevel requestedAccessLevel = PHAccessLevelReadWrite; + PHAuthorizationStatus status = + [PHPhotoLibrary authorizationStatusForAccessLevel:requestedAccessLevel]; switch (status) { case PHAuthorizationStatusNotDetermined: { [PHPhotoLibrary - requestAuthorizationForAccessLevel:PHAccessLevelReadWrite + requestAuthorizationForAccessLevel:requestedAccessLevel handler:^(PHAuthorizationStatus status) { dispatch_async(dispatch_get_main_queue(), ^{ if (status == PHAuthorizationStatusAuthorized) { From 1d95a0aae305d3d5d6d74addd57344e810199637 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Fri, 16 Dec 2022 17:13:31 -0600 Subject: [PATCH 2/3] add unit tests and update release info --- .../image_picker_ios/CHANGELOG.md | 4 ++ .../ios/RunnerTests/ImagePickerPluginTests.m | 42 +++++++++++++++++++ .../image_picker_ios/pubspec.yaml | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker_ios/CHANGELOG.md b/packages/image_picker/image_picker_ios/CHANGELOG.md index bff6dd7394f2..0ab4e328db1d 100644 --- a/packages/image_picker/image_picker_ios/CHANGELOG.md +++ b/packages/image_picker/image_picker_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.6+3 + +* Fix authorization status check for iOS14+ so it includes PHAuthorizationStatusLimited. + ## 0.8.6+2 * Fixes issue where selectable images of certain types (such as ProRAW images) could not be loaded. diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m index 320582b0f8a3..8b3cd57009cd 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m @@ -302,4 +302,46 @@ - (void)testPluginMultiImagePathHasItem { XCTAssertEqual(pickImageResult, pathList); } +- (void)testPickImageRequestAuthorization API_AVAILABLE(ios(14)) { + id mockPhotoLibrary = OCMClassMock([PHPhotoLibrary class]); + OCMStub([mockPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite]) + .andReturn(PHAuthorizationStatusNotDetermined); + OCMExpect([mockPhotoLibrary requestAuthorizationForAccessLevel:PHAccessLevelReadWrite + handler:OCMOCK_ANY]); + + FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init]; + + [plugin pickImageWithSource:[FLTSourceSpecification makeWithType:FLTSourceTypeGallery + camera:FLTSourceCameraFront] + maxSize:[[FLTMaxSize alloc] init] + quality:nil + fullMetadata:@YES + completion:^(NSString *result, FlutterError *error){ + }]; + OCMVerifyAll(mockPhotoLibrary); +} + +- (void)testPickImageAuthorizationDenied API_AVAILABLE(ios(14)) { + id mockPhotoLibrary = OCMClassMock([PHPhotoLibrary class]); + OCMStub([mockPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite]) + .andReturn(PHAuthorizationStatusDenied); + + FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init]; + + XCTestExpectation *resultExpectation = [self expectationWithDescription:@"result"]; + + [plugin pickImageWithSource:[FLTSourceSpecification makeWithType:FLTSourceTypeGallery + camera:FLTSourceCameraFront] + maxSize:[[FLTMaxSize alloc] init] + quality:nil + fullMetadata:@YES + completion:^(NSString *result, FlutterError *error) { + XCTAssertNil(result); + XCTAssertEqualObjects(error.code, @"photo_access_denied"); + XCTAssertEqualObjects(error.message, @"The user did not allow photo access."); + [resultExpectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:30 handler:nil]; +} + @end diff --git a/packages/image_picker/image_picker_ios/pubspec.yaml b/packages/image_picker/image_picker_ios/pubspec.yaml index e1b389161d75..44c00d7426e9 100755 --- a/packages/image_picker/image_picker_ios/pubspec.yaml +++ b/packages/image_picker/image_picker_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: image_picker_ios description: iOS implementation of the image_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.6+2 +version: 0.8.6+3 environment: sdk: ">=2.14.0 <3.0.0" From e9ae12f88fc848aea1fb258b279272dfd42d1165 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Wed, 21 Dec 2022 15:28:09 -0600 Subject: [PATCH 3/3] update release info --- packages/image_picker/image_picker_ios/CHANGELOG.md | 4 ++++ packages/image_picker/image_picker_ios/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker_ios/CHANGELOG.md b/packages/image_picker/image_picker_ios/CHANGELOG.md index f51f46cac34c..48d03e7bccbe 100644 --- a/packages/image_picker/image_picker_ios/CHANGELOG.md +++ b/packages/image_picker/image_picker_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.6+4 + +* Fix authorization status check for iOS14+ so it includes `PHAuthorizationStatusLimited`. + ## 0.8.6+3 * Returns error on image load failure. diff --git a/packages/image_picker/image_picker_ios/pubspec.yaml b/packages/image_picker/image_picker_ios/pubspec.yaml index 44c00d7426e9..e8ebcfd3756c 100755 --- a/packages/image_picker/image_picker_ios/pubspec.yaml +++ b/packages/image_picker/image_picker_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: image_picker_ios description: iOS implementation of the image_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.6+3 +version: 0.8.6+4 environment: sdk: ">=2.14.0 <3.0.0"