Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates CTPicker.m #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
80 changes: 42 additions & 38 deletions src/ios/CTPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
}];
}
Expand All @@ -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;
Expand Down