This is an automated email from the ASF dual-hosted git repository.
manuelbeck pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git
The following commit(s) were added to refs/heads/master by this push:
new b75cff8 ios: rename method `finalizePHPickerImage:` and document it
(#947)
b75cff8 is described below
commit b75cff893e1a1f22b50ff1114abc43fdb69b3f54
Author: Manuel Beck <[email protected]>
AuthorDate: Fri Jan 30 17:49:52 2026 +0100
ios: rename method `finalizePHPickerImage:` and document it (#947)
- Rename to `processPHPickerImage:` since it does rotating, scaling and
cropping and prepare the metadata
- Document the method and code
---
src/ios/CDVCamera.h | 2 +-
src/ios/CDVCamera.m | 15 ++++++++++++---
tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m | 6 +++---
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/ios/CDVCamera.h b/src/ios/CDVCamera.h
index 8f57060..9892fc8 100644
--- a/src/ios/CDVCamera.h
+++ b/src/ios/CDVCamera.h
@@ -137,7 +137,7 @@ 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));
+- (void)processPHPickerImage:(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..29daa7f 100644
--- a/src/ios/CDVCamera.m
+++ b/src/ios/CDVCamera.m
@@ -413,7 +413,7 @@ static NSString* MIME_JPEG = @"image/jpeg";
return;
}
- [weakSelf finalizePHPickerImage:[UIImage
imageWithData:imageData]
+ [weakSelf processPHPickerImage:[UIImage
imageWithData:imageData]
metadata:[weakSelf
convertImageMetadata:imageData]
callbackId:callbackId
options:pictureOptions];
@@ -422,12 +422,18 @@ static NSString* MIME_JPEG = @"image/jpeg";
}];
}
-- (void)finalizePHPickerImage:(UIImage*)image
+/**
+ Processes an image obtained from PHPickerViewController according to
specified pictureOptions,
+ after it returns the CDVPluginResult.
+ The processing of the image is similar what retrieveImage: and
processImage: is doing for UIImagePickerController.
+*/
+- (void)processPHPickerImage:(UIImage*)image
metadata:(NSDictionary*)metadata
callbackId:(NSString*)callbackId
options:(CDVPictureOptions*)options
API_AVAILABLE(ios(14))
{
// Process image according to options
+ // The same is done in retrieveImage:
UIImage *processedImage = image;
if (options.correctOrientation) {
@@ -446,7 +452,8 @@ static NSString* MIME_JPEG = @"image/jpeg";
}
}
- // Store metadata, which will be processed in resultForImage
+ // Prepare self.metadata, which replicates the logic from processImage:
for the UIImagePickerController
+ // self.metadata which will be set to the image in resultForImage:
if (metadata.count > 0) {
self.metadata = [NSMutableDictionary dictionary];
@@ -471,9 +478,11 @@ static NSString* MIME_JPEG = @"image/jpeg";
__weak CDVCamera* weakSelf = self;
// Create info dictionary similar to UIImagePickerController
+ // Will be used in retrieveImage: to get the image and do processing like
here was done
NSMutableDictionary *info = [@{ UIImagePickerControllerOriginalImage :
processedImage } mutableCopy];
if (metadata.count > 0) {
+ // This is not used anywhere and can be removed
info[UIImagePickerControllerMediaMetadata] = metadata;
}
diff --git a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m
b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m
index 68e0421..ac1b7ef 100644
--- a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m
+++ b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m
@@ -563,9 +563,9 @@
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]);
+ // Test that processPHPickerImage method exists
+ SEL processPHPickerImageSelector =
@selector(processPHPickerImage:metadata:callbackId:options:);
+ XCTAssertTrue([self.plugin
respondsToSelector:processPHPickerImageSelector]);
}
#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]