Share Extension - Get exif data/metadata(location) of image.

I have created a share extension for my app to share images directly from photos app. However I also needs to fetch the metadata specifically location of the image shared. When sharing from the app I am able to fetch location from UIImagePickerController but when using share extension I am just getting the UIImage object, not the dictionary. Is there a way I can get the location for images shared from extension as well?

Here is my code:

- (void)didSelectPost {
    
    for (int i=0; i<self.extensionContext.inputItems.count; i++) {
        NSExtensionItem *item = self.extensionContext.inputItems[i];
        for (int j=0; j<item.attachments.count; j++) {
            NSItemProvider *itemProvider = item.attachments[j];
            
            if ([itemProvider hasItemConformingToTypeIdentifier: (NSString *)kUTTypeImage]) {
                [itemProvider loadItemForTypeIdentifier: (NSString *)kUTTypeImage options: nil completionHandler: ^(NSData* image, NSError* error) {
                    [self newSighting:image location:nil isSevere:false];
                    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
                }];
            }
        }
    }
} 

You can retrieve the metadata from the image file. For example:

if itemProvider.hasItemConformingToTypeIdentifier(UTType.image.identifier) {
    itemProvider.loadDataRepresentation(forTypeIdentifier: UTType.image.identifier) { data, error in
        guard let data = data,
              let cgImageSource = CGImageSourceCreateWithData(data as CFData, nil),
              let properties = CGImageSourceCopyPropertiesAtIndex(cgImageSource, 0, nil) else { return }
        print(properties)
    }
}
Share Extension - Get exif data/metadata(location) of image.
 
 
Q