This is an automated email from the ASF dual-hosted git repository. manuelbeck pushed a commit to branch pr-ios-resolve-method-finalizePHPickerImage in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git
commit 9a69a38b04186c39b66b707f3bf1c7369451a5d2 Author: Manuel Beck <[email protected]> AuthorDate: Thu Jan 29 20:34:20 2026 +0100 fix(ios): resolve method `finalizePHPickerImage` - The code for processing the image according picture options and processing the metadata is not necessary to be done in an extra method --- src/ios/CDVCamera.h | 1 - src/ios/CDVCamera.m | 114 +++++++++------------ .../CDVCameraTest/CDVCameraLibTests/CameraTest.m | 4 - 3 files changed, 51 insertions(+), 68 deletions(-) diff --git a/src/ios/CDVCamera.h b/src/ios/CDVCamera.h index 8f57060..6a915d9 100644 --- a/src/ios/CDVCamera.h +++ b/src/ios/CDVCamera.h @@ -137,7 +137,6 @@ typedef NSUInteger CDVMediaType; // PHPickerViewController specific methods (iOS 14+) #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 // Always true on XCode12+ - (void)showPHPicker:(NSString*)callbackId withOptions:(CDVPictureOptions*)pictureOptions API_AVAILABLE(ios(14)); -- (void)finalizePHPickerImage:(UIImage*)image metadata:(NSDictionary*)metadata callbackId:(NSString*)callbackId options:(CDVPictureOptions*)options API_AVAILABLE(ios(14)); // PHPickerViewControllerDelegate method - (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results API_AVAILABLE(ios(14)); #endif diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index 79a78b1..934bff3 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -413,75 +413,63 @@ static NSString* MIME_JPEG = @"image/jpeg"; return; } - [weakSelf finalizePHPickerImage:[UIImage imageWithData:imageData] - metadata:[weakSelf convertImageMetadata:imageData] - callbackId:callbackId - options:pictureOptions]; - }]; - } - }]; -} - -- (void)finalizePHPickerImage:(UIImage*)image - metadata:(NSDictionary*)metadata - callbackId:(NSString*)callbackId - options:(CDVPictureOptions*)options API_AVAILABLE(ios(14)) -{ - // Process image according to options - UIImage *processedImage = image; - - if (options.correctOrientation) { - processedImage = [processedImage imageCorrectedForCaptureOrientation]; - } - - // Scale with optional cropping - if ((options.targetSize.width > 0) && (options.targetSize.height > 0)) { - // Scale and crop to target size - if (options.cropToSize) { - processedImage = [processedImage imageByScalingAndCroppingForSize:options.targetSize]; + // Process image according to pictureOptions + UIImage *processedImage = [UIImage imageWithData:imageData]; + + if (pictureOptions.correctOrientation) { + processedImage = [processedImage imageCorrectedForCaptureOrientation]; + } + + // Scale with optional cropping + if ((pictureOptions.targetSize.width > 0) && (pictureOptions.targetSize.height > 0)) { + // Scale and crop to target size + if (pictureOptions.cropToSize) { + processedImage = [processedImage imageByScalingAndCroppingForSize:pictureOptions.targetSize]; - // Scale with no cropping - } else { - processedImage = [processedImage imageByScalingNotCroppingForSize:options.targetSize]; - } - } + // Scale with no cropping + } else { + processedImage = [processedImage imageByScalingNotCroppingForSize:pictureOptions.targetSize]; + } + } - // Store metadata, which will be processed in resultForImage - if (metadata.count > 0) { - self.metadata = [NSMutableDictionary dictionary]; + // Store metadata of exif, tiff, gps in self.metadata, which will be processed in resultForImage + NSDictionary *metadata = [weakSelf convertImageMetadata:imageData]; + + if (metadata.count > 0) { + self.metadata = [NSMutableDictionary dictionary]; - NSDictionary *exif = metadata[(NSString *)kCGImagePropertyExifDictionary]; - if (exif.count > 0) { - self.metadata[(NSString *)kCGImagePropertyExifDictionary] = [exif mutableCopy]; - } + NSDictionary *exif = metadata[(NSString *)kCGImagePropertyExifDictionary]; + if (exif.count > 0) { + self.metadata[(NSString *)kCGImagePropertyExifDictionary] = [exif mutableCopy]; + } - NSDictionary *tiff = metadata[(NSString *)kCGImagePropertyTIFFDictionary]; - if (tiff.count > 0) { - self.metadata[(NSString *)kCGImagePropertyTIFFDictionary] = [tiff mutableCopy]; - } + NSDictionary *tiff = metadata[(NSString *)kCGImagePropertyTIFFDictionary]; + if (tiff.count > 0) { + self.metadata[(NSString *)kCGImagePropertyTIFFDictionary] = [tiff mutableCopy]; + } - NSDictionary *gps = metadata[(NSString *)kCGImagePropertyGPSDictionary]; - if (gps.count > 0) { - self.metadata[(NSString *)kCGImagePropertyGPSDictionary] = [gps mutableCopy]; + NSDictionary *gps = metadata[(NSString *)kCGImagePropertyGPSDictionary]; + if (gps.count > 0) { + self.metadata[(NSString *)kCGImagePropertyGPSDictionary] = [gps mutableCopy]; + } + } + + // Return CDVPluginResult to WebView + // Create info dictionary similar to UIImagePickerController + NSMutableDictionary *info = [@{ UIImagePickerControllerOriginalImage : processedImage } mutableCopy]; + + if (metadata.count > 0) { + info[UIImagePickerControllerMediaMetadata] = metadata; + } + + // Process and return result + [self resultForImage:pictureOptions info:info completion:^(CDVPluginResult* pluginResult) { + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; + weakSelf.hasPendingOperation = NO; + weakSelf.pickerController = nil; + }]; + }]; } - } - - // Return Cordova result to WebView - // Needed weakSelf for completion block - __weak CDVCamera* weakSelf = self; - - // Create info dictionary similar to UIImagePickerController - NSMutableDictionary *info = [@{ UIImagePickerControllerOriginalImage : processedImage } mutableCopy]; - - if (metadata.count > 0) { - info[UIImagePickerControllerMediaMetadata] = metadata; - } - - // Process and return result - [self resultForImage:options info:info completion:^(CDVPluginResult* pluginResult) { - [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; - weakSelf.hasPendingOperation = NO; - weakSelf.pickerController = nil; }]; } #endif diff --git a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m index 68e0421..01a953b 100644 --- a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m +++ b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m @@ -562,10 +562,6 @@ // Test that processPHPickerImage method exists SEL processSelector = @selector(processPHPickerImage:assetIdentifier:callbackId:options:); XCTAssertTrue([self.plugin respondsToSelector:processSelector]); - - // Test that finalizePHPickerImage method exists - SEL finalizeSelector = @selector(finalizePHPickerImage:metadata:callbackId:options:); - XCTAssertTrue([self.plugin respondsToSelector:finalizeSelector]); } #endif --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
