Skip to content

Commit

Permalink
Update CDVCamera.m
Browse files Browse the repository at this point in the history
  • Loading branch information
l0stpenguin committed Sep 16, 2019
1 parent d7f5668 commit e1d057d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/ios/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,21 @@ - (void)imagePickerControllerReturnImageResult
{
CDVPictureOptions* options = self.pickerController.pictureOptions;
CDVPluginResult* result = nil;
NSData* data = [self.data copy];

NSMutableData *dest_data = [NSMutableData data];

if (self.metadata) {
CGImageSourceRef sourceImage = CGImageSourceCreateWithData((__bridge CFDataRef)self.data, NULL);
CFStringRef sourceType = CGImageSourceGetType(sourceImage);

CGImageDestinationRef destinationImage = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)self.data, sourceType, 1, NULL);
CGImageDestinationRef destinationImage = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data, sourceType, 1, NULL);
CGImageDestinationAddImageFromSource(destinationImage, sourceImage, 0, (__bridge CFDictionaryRef)self.metadata);
CGImageDestinationFinalize(destinationImage);

CFRelease(sourceImage);
CFRelease(destinationImage);
} else{
dest_data = [self.data mutableCopy];
}

switch (options.destinationType) {
Expand All @@ -691,7 +695,7 @@ - (void)imagePickerControllerReturnImageResult
NSString* filePath = [self tempFilePath:extension];

// save file
if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
if (![dest_data writeToFile:filePath options:NSAtomicWrite error:&err]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
}
else {
Expand All @@ -701,7 +705,7 @@ - (void)imagePickerControllerReturnImageResult
break;
case DestinationTypeDataUrl:
{
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:toBase64(data)];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:toBase64(dest_data)];
}
break;
case DestinationTypeNativeUri:
Expand All @@ -717,7 +721,7 @@ - (void)imagePickerControllerReturnImageResult
self.pickerController = nil;
self.data = nil;
self.metadata = nil;
data = nil;
dest_data = nil;
if (options.saveToPhotoAlbum) {
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library writeImageDataToSavedPhotosAlbum:self.data metadata:self.metadata completionBlock:nil];
Expand Down

0 comments on commit e1d057d

Please sign in to comment.