-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker] Fix check for iOS 14+ authorization status #6845
Conversation
So I'm unsure of how to test this change. Since the behavior and UI for Also, I'm waiting to update the changelog/pubspec since I have a different PR for the image_picker that should land soon. |
Ugh, sorry, the - (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];
} The first one would fail via |
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.
LGTM!
PHAccessLevel requestedAccessLevel = PHAccessLevelReadWrite; | ||
PHAuthorizationStatus status = | ||
[PHPhotoLibrary authorizationStatusForAccessLevel:requestedAccessLevel]; |
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.
Up to you, but it might be clearer to get rid of the local variable and pass in PHAccessLevelReadWrite
in two places. Accessing an enum is so cheap there's no reason to cache it.
PHAccessLevel requestedAccessLevel = PHAccessLevelReadWrite; | |
PHAuthorizationStatus status = | |
[PHPhotoLibrary authorizationStatusForAccessLevel:requestedAccessLevel]; | |
PHAuthorizationStatus status = | |
[PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite]; |
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.
LGTM!
* 986b16a2d Roll Flutter from 9fb1ae8 to a45a2f3 (19 revisions) (flutter/plugins#6879) * 9dc053428 expose webresourceeerrortype (flutter/plugins#6877) * 9ee9db676 [image_picker] Fix check for iOS 14+ authorization status (flutter/plugins#6845) * 3eba2bf69 Roll Flutter from a45a2f3 to e766ad0 (7 revisions) (flutter/plugins#6880)
…#117653) * 986b16a2d Roll Flutter from 9fb1ae8 to a45a2f3 (19 revisions) (flutter/plugins#6879) * 9dc053428 expose webresourceeerrortype (flutter/plugins#6877) * 9ee9db676 [image_picker] Fix check for iOS 14+ authorization status (flutter/plugins#6845) * 3eba2bf69 Roll Flutter from a45a2f3 to e766ad0 (7 revisions) (flutter/plugins#6880)
…#117653) * 986b16a2d Roll Flutter from 9fb1ae8 to a45a2f3 (19 revisions) (flutter/plugins#6879) * 9dc053428 expose webresourceeerrortype (flutter/plugins#6877) * 9ee9db676 [image_picker] Fix check for iOS 14+ authorization status (flutter/plugins#6845) * 3eba2bf69 Roll Flutter from a45a2f3 to e766ad0 (7 revisions) (flutter/plugins#6880)
* fix check for authorization status * add unit tests and update release info * update release info
Replace
[PHPhotoLibrary authorizationStatus]
with[PHPhotoLibrary authorizationStatusForAccessLevel:]
for iOS 14+.According to WWDC 2020 video "Handle the Limited Photos Library in your app",
authorizationStatus
is deprecated and will not return the newerPHAuthorizationStatusLimited
.Fixes flutter/flutter#113681.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.