-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[image_picker] Removes use of PHAsset when using PHPickerViewController #8020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
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 |
---|---|---|
|
@@ -113,11 +113,7 @@ - (void)launchPHPickerWithContext:(nonnull FLTImagePickerMethodCallContext *)con | |
pickerViewController.presentationController.delegate = self; | ||
self.callContext = context; | ||
|
||
if (context.requestFullMetadata) { | ||
[self checkPhotoAuthorizationWithPHPicker:pickerViewController]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does anything use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think anything uses this, removed. |
||
} else { | ||
[self showPhotoLibraryWithPHPicker:pickerViewController]; | ||
} | ||
[self showPhotoLibraryWithPHPicker:pickerViewController]; | ||
} | ||
|
||
- (void)launchUIImagePickerWithSource:(nonnull FLTSourceSpecification *)source | ||
|
@@ -390,40 +386,6 @@ - (void)checkPhotoAuthorizationWithImagePicker:(UIImagePickerController *)imageP | |
} | ||
} | ||
|
||
- (void)checkPhotoAuthorizationWithPHPicker:(PHPickerViewController *)pickerViewController | ||
API_AVAILABLE(ios(14)) { | ||
PHAccessLevel requestedAccessLevel = PHAccessLevelReadWrite; | ||
PHAuthorizationStatus status = | ||
[PHPhotoLibrary authorizationStatusForAccessLevel:requestedAccessLevel]; | ||
switch (status) { | ||
case PHAuthorizationStatusNotDetermined: { | ||
[PHPhotoLibrary | ||
requestAuthorizationForAccessLevel:requestedAccessLevel | ||
handler:^(PHAuthorizationStatus status) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
if (status == PHAuthorizationStatusAuthorized) { | ||
[self showPhotoLibraryWithPHPicker:pickerViewController]; | ||
} else if (status == PHAuthorizationStatusLimited) { | ||
[self showPhotoLibraryWithPHPicker:pickerViewController]; | ||
} else { | ||
[self errorNoPhotoAccess:status]; | ||
} | ||
}); | ||
}]; | ||
break; | ||
} | ||
case PHAuthorizationStatusAuthorized: | ||
case PHAuthorizationStatusLimited: | ||
[self showPhotoLibraryWithPHPicker:pickerViewController]; | ||
break; | ||
case PHAuthorizationStatusDenied: | ||
case PHAuthorizationStatusRestricted: | ||
default: | ||
[self errorNoPhotoAccess:status]; | ||
break; | ||
} | ||
} | ||
|
||
- (void)errorNoCameraAccess:(AVAuthorizationStatus)status { | ||
switch (status) { | ||
case AVAuthorizationStatusRestricted: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,64 +128,20 @@ - (void)start { | |
- (void)processImage:(NSData *)pickerImageData API_AVAILABLE(ios(14)) { | ||
UIImage *localImage = [[UIImage alloc] initWithData:pickerImageData]; | ||
|
||
PHAsset *originalAsset; | ||
// Only if requested, fetch the full "PHAsset" metadata, which requires "Photo Library Usage" | ||
// permissions. | ||
if (self.requestFullMetadata) { | ||
originalAsset = [FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:self.result]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does anything use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed function and a test that uses it. |
||
} | ||
|
||
if (self.maxWidth != nil || self.maxHeight != nil) { | ||
localImage = [FLTImagePickerImageUtil scaledImage:localImage | ||
maxWidth:self.maxWidth | ||
maxHeight:self.maxHeight | ||
isMetadataAvailable:YES]; | ||
} | ||
if (originalAsset) { | ||
void (^resultHandler)(NSData *imageData, NSString *dataUTI, NSDictionary *info) = | ||
^(NSData *_Nullable imageData, NSString *_Nullable dataUTI, NSDictionary *_Nullable info) { | ||
// maxWidth and maxHeight are used only for GIF images. | ||
NSString *savedPath = [FLTImagePickerPhotoAssetUtil | ||
saveImageWithOriginalImageData:imageData | ||
image:localImage | ||
maxWidth:self.maxWidth | ||
maxHeight:self.maxHeight | ||
imageQuality:self.desiredImageQuality]; | ||
[self completeOperationWithPath:savedPath error:nil]; | ||
}; | ||
if (@available(iOS 13.0, *)) { | ||
[[PHImageManager defaultManager] | ||
requestImageDataAndOrientationForAsset:originalAsset | ||
options:nil | ||
resultHandler:^(NSData *_Nullable imageData, | ||
NSString *_Nullable dataUTI, | ||
CGImagePropertyOrientation orientation, | ||
NSDictionary *_Nullable info) { | ||
resultHandler(imageData, dataUTI, info); | ||
}]; | ||
} else { | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
[[PHImageManager defaultManager] | ||
requestImageDataForAsset:originalAsset | ||
options:nil | ||
resultHandler:^(NSData *_Nullable imageData, NSString *_Nullable dataUTI, | ||
UIImageOrientation orientation, NSDictionary *_Nullable info) { | ||
resultHandler(imageData, dataUTI, info); | ||
}]; | ||
#pragma clang diagnostic pop | ||
} | ||
} else { | ||
// Image picked without an original asset (e.g. User pick image without permission) | ||
// maxWidth and maxHeight are used only for GIF images. | ||
NSString *savedPath = | ||
[FLTImagePickerPhotoAssetUtil saveImageWithOriginalImageData:pickerImageData | ||
image:localImage | ||
maxWidth:self.maxWidth | ||
maxHeight:self.maxHeight | ||
imageQuality:self.desiredImageQuality]; | ||
[self completeOperationWithPath:savedPath error:nil]; | ||
} | ||
// maxWidth and maxHeight are used only for GIF images. | ||
NSString *savedPath = | ||
[FLTImagePickerPhotoAssetUtil saveImageWithOriginalImageData:pickerImageData | ||
image:localImage | ||
maxWidth:self.maxWidth | ||
maxHeight:self.maxHeight | ||
imageQuality:self.desiredImageQuality]; | ||
[self completeOperationWithPath:savedPath error:nil]; | ||
} | ||
|
||
/// Processes the video. | ||
|
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.
Should we rename this test to something like
testPickImageDoesntRequestAuthorization
?