When getting the PHPickerResult from user selecting media in the Photos app, how to check file extension?

when I get results from picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) and I load the image using itemProvider .loadFileRepresentation (the itemProvider is the NSItemProvider provided by the PHPickerResult)

will the url that's returned by this method be guaranteed to have the file extension ie, "file://image.jpeg" not "file://image"

I want to know if i need to just check the extension to know its file type. (FYI in case this makes a difference, im only interested in user screenshots and screenrecordings)

Answered by DTS Engineer in 831464022

Whether you can rely on the format of the returned url is not clear in the documentation. However, you can call hasItemConformingToTypeIdentifier(_:) method on the NSItemProvider to find out if the NSItemProvider is able to provide the formats you're interested in receiving.

Though, I should mention, I'm not sure there's a specifically documented file type for screenshots. That may be subject to change without notice (I'll update this thread if I find documentation about that).

Worth noting, screenshots created in macOS Sequoia 15.3.2 (24D81) and in iOS 18.3.2 have the User Comment in the EXIF data set to the string "Screenshot" (I'll update this thread if I find documentation about that).

If you're like to have an officially documented way of determining if an image file was created from a screenshot or a video is a screen recording won't you please consider filing an enhancement request asking for that functionality. You can file an enhancement request using Feedback Assistant. Once you file the request, please post the Feedback number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

I would not recommend introspecting and relying on the file extension for this URL. While it may in practice often have the correct extensions this is not considered part of the API and could change in the future. Additionally there are many different valid extensions for various image and video types.

Is this what your ultimate aim is? To limit the PHPicker to only show you screenshots and screen recording?

(FYI in case this makes a difference, im only interested in user screenshots and screenrecordings)

Are you setting the PHPickerFilers for these on your PHPickerConfiguration? That could be one option if you are trying to have the user choose from screenshots or screen recordings from their library.

PHPickerFilter screen recordings documentation

PHPickerFilter screenshot documentation

Yes my aim is to select screenshots and screen recordings. Now is the url returned for these assets always going to have the file extension? I would like to copy these assets to my apps file directory and include an extension, and it would be great if it's already included in the provided url.

Whether you can rely on the format of the returned url is not clear in the documentation. However, you can call hasItemConformingToTypeIdentifier(_:) method on the NSItemProvider to find out if the NSItemProvider is able to provide the formats you're interested in receiving.

Though, I should mention, I'm not sure there's a specifically documented file type for screenshots. That may be subject to change without notice (I'll update this thread if I find documentation about that).

Worth noting, screenshots created in macOS Sequoia 15.3.2 (24D81) and in iOS 18.3.2 have the User Comment in the EXIF data set to the string "Screenshot" (I'll update this thread if I find documentation about that).

If you're like to have an officially documented way of determining if an image file was created from a screenshot or a video is a screen recording won't you please consider filing an enhancement request asking for that functionality. You can file an enhancement request using Feedback Assistant. Once you file the request, please post the Feedback number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

Written by DTS Engineer in 831464022
If you're like to have an officially documented way of determining if an image file was created from a screenshot or a video is a screen recording won't you please consider filing an enhancement request asking for that functionality

Oh no ! for me im interested in determining its file type , like jpeg, png, mp4, mov etc.. in an efficient way. So im asking if the url would have the file extension. I know theres hasItemConfirmingToTypeIdentifier, but it would be nice if the type can be known from the url and I can copy the image with the same filename as the url straight away. (rather than checking and appending the file extension myself)

Yes, I can see your point. But, the documentation does not guarantee anything about the url so that is subject to change without notice. The best you can do there is file an enhancement request for the documentation to be updated to include specific information about the url.

for now can it be safely assumed that if its an screen shot it will be jpeg or png? i dont want to check for every possible type.. theres a lot.

while for screen records, can it be assumed to be mp4 or mov? again dont want to check so many types.

When getting the PHPickerResult from user selecting media in the Photos app, how to check file extension?
 
 
Q