shazron commented on a change in pull request #310: CB-13415 (iOS) Importing 
corrupt images using the Camera plugin crashes the app
URL: 
https://github.com/apache/cordova-plugin-camera/pull/310#discussion_r164052640
 
 

 ##########
 File path: src/ios/CDVCamera.m
 ##########
 @@ -360,7 +361,22 @@ - (NSData*)processImage:(UIImage*)image 
info:(NSDictionary*)info options:(CDVPic
         {
             if ((options.allowsEditing == NO) && (options.targetSize.width <= 
0) && (options.targetSize.height <= 0) && (options.correctOrientation == NO) && 
(([options.quality integerValue] == 100) || (options.sourceType != 
UIImagePickerControllerSourceTypeCamera))){
                 // use image unedited as requested , don't resize
-                data = UIImageJPEGRepresentation(image, 1.0);
+                  if(options.sourceType != 
UIImagePickerControllerSourceTypeCamera){
+                    NSURL *url = info[UIImagePickerControllerReferenceURL];
+                    PHFetchResult *result = [PHAsset 
fetchAssetsWithALAssetURLs:@[url] options:nil];
+                    PHAsset *asset = [result firstObject];
+                    if (asset) {
+                        PHImageManager *manager = [PHImageManager 
defaultManager];
+                        PHImageRequestOptions *option = [PHImageRequestOptions 
alloc];
+                        option.synchronous = true;
+                        [manager requestImageDataForAsset:asset options:option 
resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation 
orientation, NSDictionary *info) {
+                              data = imageData;
 
 Review comment:
   This is the error that @alsorokin pointed out. Inherently this whole PR has 
to be re-worked since here on this line, this an async block (a callback) that 
resides in a synchronous function. For this to work, the processImage function 
has to be async, and changing that is not trivial.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to