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

Commit a3818f2

Browse files
authored
[image_picker] Image picker fix alert (#3881)
1 parent d4f708b commit a3818f2

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed

packages/image_picker/image_picker/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.7.5+2
2+
* Implement `UIAlertController` with a preferredStyle of `UIAlertControllerStyleAlert` since `UIAlertView` is deprecated.
3+
14
## 0.7.5+1
25

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

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

1215
## 0.7.4
1316

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,17 @@ - (void)showCamera {
190190
animated:YES
191191
completion:nil];
192192
} else {
193-
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil)
194-
message:NSLocalizedString(@"Camera not available.", nil)
195-
delegate:nil
196-
cancelButtonTitle:NSLocalizedString(@"OK", nil)
197-
otherButtonTitles:nil] show];
193+
UIAlertController *cameraErrorAlert =
194+
[UIAlertController alertControllerWithTitle:@"Error"
195+
message:@"Camera not available."
196+
preferredStyle:UIAlertControllerStyleAlert];
197+
[cameraErrorAlert addAction:[UIAlertAction actionWithTitle:@"OK"
198+
style:UIAlertActionStyleDefault
199+
handler:^(UIAlertAction *action){
200+
}]];
201+
[[self viewControllerWithWindow:nil] presentViewController:cameraErrorAlert
202+
animated:YES
203+
completion:nil];
198204
self.result(nil);
199205
self.result = nil;
200206
_arguments = nil;
@@ -211,19 +217,16 @@ - (void)checkCameraAuthorization {
211217
case AVAuthorizationStatusNotDetermined: {
212218
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
213219
completionHandler:^(BOOL granted) {
214-
if (granted) {
215-
dispatch_async(dispatch_get_main_queue(), ^{
216-
if (granted) {
217-
[self showCamera];
218-
}
219-
});
220-
} else {
221-
dispatch_async(dispatch_get_main_queue(), ^{
220+
dispatch_async(dispatch_get_main_queue(), ^{
221+
if (granted) {
222+
[self showCamera];
223+
} else {
222224
[self errorNoCameraAccess:AVAuthorizationStatusDenied];
223-
});
224-
}
225+
}
226+
});
225227
}];
226-
}; break;
228+
break;
229+
}
227230
case AVAuthorizationStatusDenied:
228231
case AVAuthorizationStatusRestricted:
229232
default:
@@ -364,41 +367,39 @@ - (void)picker:(PHPickerViewController *)picker
364367
completionHandler:^(__kindof id<NSItemProviderReading> _Nullable image,
365368
NSError *_Nullable error) {
366369
if ([image isKindOfClass:[UIImage class]]) {
367-
if (image != nil) {
368-
__block UIImage *localImage = image;
369-
dispatch_async(dispatch_get_main_queue(), ^{
370-
PHAsset *originalAsset =
371-
[FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:result];
372-
373-
if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
374-
localImage = [FLTImagePickerImageUtil scaledImage:localImage
375-
maxWidth:maxWidth
376-
maxHeight:maxHeight
377-
isMetadataAvailable:originalAsset != nil];
378-
}
379-
380-
if (!originalAsset) {
381-
// Image picked without an original asset (e.g. User took a photo directly)
382-
[self saveImageWithPickerInfo:nil
383-
image:localImage
384-
imageQuality:desiredImageQuality];
385-
} else {
386-
[[PHImageManager defaultManager]
387-
requestImageDataForAsset:originalAsset
388-
options:nil
389-
resultHandler:^(
390-
NSData *_Nullable imageData, NSString *_Nullable dataUTI,
391-
UIImageOrientation orientation, NSDictionary *_Nullable info) {
392-
// maxWidth and maxHeight are used only for GIF images.
393-
[self saveImageWithOriginalImageData:imageData
394-
image:localImage
395-
maxWidth:maxWidth
396-
maxHeight:maxHeight
397-
imageQuality:desiredImageQuality];
398-
}];
399-
}
400-
});
401-
}
370+
__block UIImage *localImage = image;
371+
dispatch_async(dispatch_get_main_queue(), ^{
372+
PHAsset *originalAsset =
373+
[FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:result];
374+
375+
if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
376+
localImage = [FLTImagePickerImageUtil scaledImage:localImage
377+
maxWidth:maxWidth
378+
maxHeight:maxHeight
379+
isMetadataAvailable:originalAsset != nil];
380+
}
381+
382+
if (!originalAsset) {
383+
// Image picked without an original asset (e.g. User took a photo directly)
384+
[self saveImageWithPickerInfo:nil
385+
image:localImage
386+
imageQuality:desiredImageQuality];
387+
} else {
388+
[[PHImageManager defaultManager]
389+
requestImageDataForAsset:originalAsset
390+
options:nil
391+
resultHandler:^(
392+
NSData *_Nullable imageData, NSString *_Nullable dataUTI,
393+
UIImageOrientation orientation, NSDictionary *_Nullable info) {
394+
// maxWidth and maxHeight are used only for GIF images.
395+
[self saveImageWithOriginalImageData:imageData
396+
image:localImage
397+
maxWidth:maxWidth
398+
maxHeight:maxHeight
399+
imageQuality:desiredImageQuality];
400+
}];
401+
}
402+
});
402403
}
403404
}];
404405
}

packages/image_picker/image_picker/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: image_picker
22
description: Flutter plugin for selecting images from the Android and iOS image
33
library, and taking new pictures with the camera.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker
5-
version: 0.7.5+1
5+
version: 0.7.5+2
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)