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 3c12685 fix(ios): get correctly metadata with `PHPicker` (#944)
3c12685 is described below
commit 3c1268531ef9fcb85d8cff78669de9bc7052359b
Author: Manuel Beck <[email protected]>
AuthorDate: Thu Jan 29 20:11:08 2026 +0100
fix(ios): get correctly metadata with `PHPicker` (#944)
- `pickerResult.assetIdentifier` was wrongly used to get metadata, while
`PHPickerConfiguration` was initialized with `init` which will not return any
asset identifiers. Only `initWithPhotoLibrary:` would work. Since `init` is
more flexible and lets the picker return items that aren’t PHAssets (e.g.,
cloud/shared providers) we use that and do not rely anymore on
`assetIdentifier` to get the image data. The image data will now get by
`[NSItemProvider loadDataRepresentationForTypeIdenti [...]
---
src/ios/CDVCamera.m | 45 ++++++++++++++-------------------------------
1 file changed, 14 insertions(+), 31 deletions(-)
diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m
index 0ffadcd..79a78b1 100644
--- a/src/ios/CDVCamera.m
+++ b/src/ios/CDVCamera.m
@@ -298,6 +298,10 @@ static NSString* MIME_JPEG = @"image/jpeg";
{
// PHPicker must be created and presented on the main thread.
dispatch_async(dispatch_get_main_queue(), ^{
+ // Using [PHPickerConfiguration init] instead of
+ // [PHPickerConfiguration initWithPhotoLibrary:[PHPhotoLibrary
sharedPhotoLibrary]]
+ // is more open and lets the picker return items that aren’t PHAssets,
like cloud/shared providers,
+ // but will not return asset identifiers.
PHPickerConfiguration *config = [[PHPickerConfiguration alloc] init];
// Configure filter based on media type
@@ -397,43 +401,22 @@ static NSString* MIME_JPEG = @"image/jpeg";
}];
// Handle image
- } else if ([pickerResult.itemProvider canLoadObjectOfClass:[UIImage
class]]) {
- [pickerResult.itemProvider loadObjectOfClass:[UIImage class]
completionHandler:^(__kindof id<NSItemProviderReading> _Nullable object,
NSError * _Nullable error) {
+ } else if ([pickerResult.itemProvider
hasItemConformingToTypeIdentifier:UTTypeImage.identifier]) {
+ // Load image data for the NSItemProvider
+ [pickerResult.itemProvider
loadDataRepresentationForTypeIdentifier:UTTypeImage.identifier
+
completionHandler:^(NSData * _Nullable imageData, NSError * _Nullable error) {
if (error) {
- CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error
localizedDescription]];
+ CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_ERROR
+
messageAsString:[error localizedDescription]];
[weakSelf.commandDelegate sendPluginResult:result
callbackId:callbackId];
weakSelf.hasPendingOperation = NO;
return;
}
- UIImage *image = (UIImage *)object;
-
- // Fetch metadata if asset identifier is available
- if (pickerResult.assetIdentifier) {
- PHFetchResult *result = [PHAsset
fetchAssetsWithLocalIdentifiers:@[pickerResult.assetIdentifier] options:nil];
- PHAsset *asset = result.firstObject;
-
- if (asset) {
- PHImageRequestOptions *imageOptions =
[[PHImageRequestOptions alloc] init];
- imageOptions.synchronous = YES;
- imageOptions.networkAccessAllowed = YES;
-
- [[PHImageManager defaultManager]
requestImageDataAndOrientationForAsset:asset
-
options:imageOptions
-
resultHandler:^(NSData *_Nullable imageData, NSString *_Nullable dataUTI,
CGImagePropertyOrientation orientation, NSDictionary *_Nullable info) {
- NSDictionary *metadata = imageData ? [weakSelf
convertImageMetadata:imageData] : nil;
- [weakSelf finalizePHPickerImage:image
- metadata:metadata
- callbackId:callbackId
- options:pictureOptions];
- }];
-
- return;
- }
- }
-
- // No metadata available
- [self finalizePHPickerImage:image metadata:nil
callbackId:callbackId options:pictureOptions];
+ [weakSelf finalizePHPickerImage:[UIImage
imageWithData:imageData]
+ metadata:[weakSelf
convertImageMetadata:imageData]
+ callbackId:callbackId
+ options:pictureOptions];
}];
}
}];
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]