diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index ac30dec24..a410ed599 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -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) { @@ -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 { @@ -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: @@ -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];