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/example/ios/RunnerTests/ImagePickerPluginTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m index 14491b221d29..16b9932a7eaf 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 @@ -397,4 +397,46 @@ - (void)testSavesImages API_AVAILABLE(ios(14)) { [self waitForExpectationsWithTimeout:30 handler:nil]; } +- (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/ios/Classes/FLTImagePickerPlugin.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m index 68230edb8b52..e910f8fc333b 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m @@ -365,11 +365,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) { 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"