From e40fbe94e572f3d698e4de964f1c653e892aba5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?1-1-3=E3=82=B7=E3=82=B9?= Date: Thu, 13 Oct 2016 18:11:09 +0900 Subject: [PATCH] Updates CTPicker.m --- src/ios/CTPicker.m | 80 ++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/ios/CTPicker.m b/src/ios/CTPicker.m index 6b62024b..59fde5a1 100644 --- a/src/ios/CTPicker.m +++ b/src/ios/CTPicker.m @@ -61,7 +61,7 @@ - (void) getPictures:(CDVInvokedUrlCommand *)command { // Display the picker in the main thread. __weak CTPicker* weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf.viewController presentViewController:imagePicker animated:YES completion:nil]; + [weakSelf.viewController presentViewController:imagePicker animated:YES completion:nil]; }); }]; } @@ -79,45 +79,49 @@ - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerControlle __block NSMutableArray *resultStrings = [[NSMutableArray alloc] init]; for (PHAsset *asset in assets) { - NSString *filePath = [self tempFilePath:@"jpg"]; - NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO]; - - CGSize targetSize; - if (self.width == 0 && self.height == 0) { - targetSize = PHImageManagerMaximumSize; - } else { - targetSize = CGSizeMake(self.width, self.height); - } + @autoreleasepool { + NSString *filePath = [self tempFilePath:@"jpg"]; + NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO]; + + CGSize targetSize; + if (self.width == 0 && self.height == 0) { + targetSize = PHImageManagerMaximumSize; + } else { + targetSize = CGSizeMake(self.width, self.height); + } - void (^handler)(UIImage *image, NSDictionary *info) = ^void(UIImage *image, NSDictionary *info) { - UIImage *rotatedImage = [self imageByRotatingImage:image]; - - NSDictionary *options = @{ - (__bridge id)kCGImageDestinationLossyCompressionQuality: @(self.quality / 100), - (__bridge id)kCGImageMetadataShouldExcludeGPS: @(YES), - }; - CGImageDestinationRef imageDestinationRef = - CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, - kUTTypeJPEG, - 1, - NULL); - - CGImageDestinationAddImage(imageDestinationRef, rotatedImage.CGImage, (__bridge CFDictionaryRef)options); - if (CGImageDestinationFinalize(imageDestinationRef)) { - [resultStrings addObject:[fileURL absoluteString]]; - if ([resultStrings count] == [assets count]) { - CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultStrings]; - [self didFinishImagesWithResult:pluginResult]; + void (^handler)(UIImage *image, NSDictionary *info) = ^void(UIImage *image, NSDictionary *info) { + @autoreleasepool { + UIImage *rotatedImage = [self imageByRotatingImage:image]; + + NSDictionary *options = @{ + (__bridge id)kCGImageDestinationLossyCompressionQuality: @(self.quality / 100), + (__bridge id)kCGImageMetadataShouldExcludeGPS: @(YES), + }; + CGImageDestinationRef imageDestinationRef = + CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, + kUTTypeJPEG, + 1, + NULL); + + CGImageDestinationAddImage(imageDestinationRef, rotatedImage.CGImage, (__bridge CFDictionaryRef)options); + if (CGImageDestinationFinalize(imageDestinationRef)) { + [resultStrings addObject:[fileURL absoluteString]]; + if ([resultStrings count] == [assets count]) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultStrings]; + [self didFinishImagesWithResult:pluginResult]; + } + } + CFRelease(imageDestinationRef); } - } - CFRelease(imageDestinationRef); - }; - - [manager requestImageForAsset:asset - targetSize:targetSize - contentMode:PHImageContentModeAspectFill - options:options - resultHandler:handler]; + }; + + [manager requestImageForAsset:asset + targetSize:targetSize + contentMode:PHImageContentModeAspectFill + options:options + resultHandler:handler]; + } } __weak CTPicker* weakSelf = self;