iOS Share Extension gives non existent file URL

G'day, I'm working on a share extension for our iOS app where the users are able to select multiple photos or videos and choose to share it conversations inside the app. Similar to other chat apps are doing. I ran into a problem where the file URL extracted through the inputItem's attachment are non existent for some of the files. For example share extension gives file URL such as this,

file:///var/folders/4r/qlw_jjvj3w7gh5mssgzhx15w0000gp/T/com.apple.Photos/ShareKit-Exports/2918015E-B07C-4F35-9D98-86B58464DE88/B699E8DE-4965-4C0F-9D9B-4956E5E02730/IMG_1234.jpg

But there is no such file in that location. Instead there is a file named IMG_1234.png (or different file extension), for certain items in user's photo library. How does this happen? Am I supposed to query the files inside the parent directory and locate truely existing file from it by ignoring the returned file name or some other way. When the same file is shared from other apps such as airdrop, mail, notes, they seem to have no problem opening up this file and the saved file (e.g. from airdrop) has identical file name and properties (IMG_1234.png) at final destination.

Below is code snippet on how I process the extension context in my share extension.

// I'm getting first input item here, I've checked and there are no more than 1 input item for the affected assets that are causing problem
guard let itemProviders = (extensionContext?.inputItems.first as? NSExtensionItem)?.attachments else {
    return
}

var items: [Attachment] = [] // Attachment is a custom type that contains file url or image data

itemProviders.forEach { itemProvider in
    if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
        let desiredTypeIdentifier: String = kUTTypeImage as String
        
        itemProvider.loadItem(forTypeIdentifier: desiredTypeIdentifier, options: nil) { data, _ in
            if let url = data as? URL {
                items.append(.init(data: .file(url)))
// the URL returned above is incorrect for the affected items. It's reproducible every time. 
            } else if let image = data as? UIImage {
                items.append(.init(data: .memory(image)))
            }
        }
    }
}

Regards,

iOS Share Extension gives non existent file URL
 
 
Q