@@ -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 }
0 commit comments