This is an automated email from the ASF dual-hosted git repository.

manuelbeck pushed a commit to branch pr-fix-metadata-with-phpicker
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git

commit 0fbac2643b9eaaf7d576a0d3bd438f53c9e534d2
Author: Manuel Beck <[email protected]>
AuthorDate: Thu Jan 29 15:47:08 2026 +0100

    fix(ios): get correctly metadata with `PHPicker`
    
    - `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 | 43 ++++++++++++-------------------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m
index c8a893f..62d5bad 100644
--- a/src/ios/CDVCamera.m
+++ b/src/ios/CDVCamera.m
@@ -298,6 +298,8 @@ static NSString* MIME_JPEG    = @"image/jpeg";
 {
     // PHPicker must be created and presented on the main thread.
     dispatch_async(dispatch_get_main_queue(), ^{
+        // Using just [PHPickerConfiguration init] is more flexible and lets 
the picker return items
+        // that aren’t PHAssets (e.g., cloud/shared providers), but it will 
not return asset identifiers.
         PHPickerConfiguration *config = [[PHPickerConfiguration alloc] init];
 
         // Configure filter based on media type
@@ -388,43 +390,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]

Reply via email to