Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker] Image picker fix alert #3881

Merged
merged 10 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.7.6
* Implement `UIAlertController` with a preferredStyle of `UIAlertControllerStyleAlert` since `UIAlertView` is deprecated.

## 0.7.5+1

* Fixes a rotation problem where Select Photos limited access is chosen but the image that is picked
Expand All @@ -7,7 +10,7 @@ is not included selected photos and image is scaled.

* Fixes an issue where image rotation is wrong when Select Photos chose and image is scaled.
* Migrate to PHPicker for iOS 14 and higher versions to pick image from the photo library.
* Implement the limited permission to pick photo from the photo library when Select Photo is chose.
* Implement the limited permission to pick photo from the photo library when Select Photo is chosen.

## 0.7.4

Expand Down
103 changes: 52 additions & 51 deletions packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,17 @@ - (void)showCamera {
animated:YES
completion:nil];
} else {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil)
message:NSLocalizedString(@"Camera not available.", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil] show];
UIAlertController *cameraErrorAlert =
[UIAlertController alertControllerWithTitle:@"Error"
message:@"Camera not available."
preferredStyle:UIAlertControllerStyleAlert];
[cameraErrorAlert addAction:[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){
}]];
[[self viewControllerWithWindow:nil] presentViewController:cameraErrorAlert
animated:YES
completion:nil];
self.result(nil);
self.result = nil;
_arguments = nil;
Expand All @@ -211,19 +217,16 @@ - (void)checkCameraAuthorization {
case AVAuthorizationStatusNotDetermined: {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
completionHandler:^(BOOL granted) {
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
if (granted) {
[self showCamera];
}
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
if (granted) {
[self showCamera];
} else {
[self errorNoCameraAccess:AVAuthorizationStatusDenied];
});
}
}
});
}];
}; break;
break;
}
case AVAuthorizationStatusDenied:
case AVAuthorizationStatusRestricted:
default:
Expand Down Expand Up @@ -364,41 +367,39 @@ - (void)picker:(PHPickerViewController *)picker
completionHandler:^(__kindof id<NSItemProviderReading> _Nullable image,
NSError *_Nullable error) {
if ([image isKindOfClass:[UIImage class]]) {
if (image != nil) {
__block UIImage *localImage = image;
dispatch_async(dispatch_get_main_queue(), ^{
PHAsset *originalAsset =
[FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:result];

if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
localImage = [FLTImagePickerImageUtil scaledImage:localImage
maxWidth:maxWidth
maxHeight:maxHeight
isMetadataAvailable:originalAsset != nil];
}

if (!originalAsset) {
// Image picked without an original asset (e.g. User took a photo directly)
[self saveImageWithPickerInfo:nil
image:localImage
imageQuality:desiredImageQuality];
} else {
[[PHImageManager defaultManager]
requestImageDataForAsset:originalAsset
options:nil
resultHandler:^(
NSData *_Nullable imageData, NSString *_Nullable dataUTI,
UIImageOrientation orientation, NSDictionary *_Nullable info) {
// maxWidth and maxHeight are used only for GIF images.
[self saveImageWithOriginalImageData:imageData
image:localImage
maxWidth:maxWidth
maxHeight:maxHeight
imageQuality:desiredImageQuality];
}];
}
});
}
__block UIImage *localImage = image;
dispatch_async(dispatch_get_main_queue(), ^{
PHAsset *originalAsset =
[FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:result];

if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
localImage = [FLTImagePickerImageUtil scaledImage:localImage
maxWidth:maxWidth
maxHeight:maxHeight
isMetadataAvailable:originalAsset != nil];
}

if (!originalAsset) {
// Image picked without an original asset (e.g. User took a photo directly)
[self saveImageWithPickerInfo:nil
image:localImage
imageQuality:desiredImageQuality];
} else {
[[PHImageManager defaultManager]
requestImageDataForAsset:originalAsset
options:nil
resultHandler:^(
NSData *_Nullable imageData, NSString *_Nullable dataUTI,
UIImageOrientation orientation, NSDictionary *_Nullable info) {
// maxWidth and maxHeight are used only for GIF images.
[self saveImageWithOriginalImageData:imageData
image:localImage
maxWidth:maxWidth
maxHeight:maxHeight
imageQuality:desiredImageQuality];
}];
}
});
}
}];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker
description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker
version: 0.7.5+1
version: 0.7.5+2

flutter:
plugin:
Expand Down