[image_picker] Image picker fix alert (#3881)
diff --git a/packages/image_picker/image_picker/CHANGELOG.md b/packages/image_picker/image_picker/CHANGELOG.md
index 380fcf4..d453c82 100644
--- a/packages/image_picker/image_picker/CHANGELOG.md
+++ b/packages/image_picker/image_picker/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 0.7.5+2
+* 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
@@ -7,7 +10,7 @@
* 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
diff --git a/packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m b/packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
index 2a9e70c..25ddaf4 100644
--- a/packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
+++ b/packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
@@ -190,11 +190,17 @@
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;
@@ -211,19 +217,16 @@
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:
@@ -364,41 +367,39 @@
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];
+ __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 (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];
- }];
- }
- });
- }
+ 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];
+ }];
+ }
+ });
}
}];
}
diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml
index fa6f653..408045d 100755
--- a/packages/image_picker/image_picker/pubspec.yaml
+++ b/packages/image_picker/image_picker/pubspec.yaml
@@ -2,7 +2,7 @@
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: