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

fix(ios): corrupted image on ios 13 #501

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "cordova-plugin-camera",
"version": "4.1.1-dev",
"name": "@spoonconsulting/cordova-plugin-camera",
"version": "4.1.3",
"description": "Cordova Camera Plugin",
"types": "./types/index.d.ts",
"cordova": {
"id": "cordova-plugin-camera",
"id": "@spoonconsulting/cordova-plugin-camera",
"platforms": [
"android",
"ios",
Expand All @@ -15,10 +15,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/apache/cordova-plugin-camera"
},
"bugs": {
"url": "https://github.com/apache/cordova-plugin-camera/issues"
"url": "https://github.com/spoonconsulting/cordova-plugin-camera"
},
"keywords": [
"cordova",
Expand All @@ -34,7 +31,7 @@
"test": "npm run eslint",
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
},
"author": "Apache Software Foundation",
"author": "Apache Software Foundation & spoonconsulting",
"license": "Apache-2.0",
"engines": {
"cordovaDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-camera"
version="4.1.1-dev">
id="@spoonconsulting/cordova-plugin-camera"
version="4.1.3">
<name>Camera</name>
<description>Cordova Camera Plugin</description>
<license>Apache 2.0</license>
Expand Down
12 changes: 8 additions & 4 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;

NSMutableData *imageDataWithExif = [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)imageDataWithExif, sourceType, 1, NULL);
CGImageDestinationAddImageFromSource(destinationImage, sourceImage, 0, (__bridge CFDictionaryRef)self.metadata);
CGImageDestinationFinalize(destinationImage);

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

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

// save file
if (![self.data writeToFile:filePath options:NSAtomicWrite error:&err]) {
if (![imageDataWithExif 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(self.data)];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:toBase64(imageDataWithExif)];
}
break;
case DestinationTypeNativeUri:
Expand All @@ -717,7 +721,7 @@ - (void)imagePickerControllerReturnImageResult
self.pickerController = nil;
self.data = nil;
self.metadata = nil;

imageDataWithExif = nil;
if (options.saveToPhotoAlbum) {
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library writeImageDataToSavedPhotosAlbum:self.data metadata:self.metadata completionBlock:nil];
Expand Down