PHPickerViewController crashes when configuration has preselectedAssetIdentifiers

PHPickerViewController crashes with the error 'Picker's configuration is not a valid configuration.' when I try to use PHPickerViewController with a configuration that has preselectedAssetIdentifiers specified, and I can't figure out why.

The identifier looks like "12345678-1234-1234-123456789012/L0/001", and I'm getting it from PHPickerResult.assetIdentifier. The exact same code works if I specify preselectedAssetIdentifiers as an empty array.

I was worried that it was just undocumented that this feature required full photo library permissions, but after giving .readWrite permissions I still experience the issue.

My iPhone 13 Pro is running 15.4.1.

The only lead on this I've found is https://stackoverflow.com/questions/71765492/pickers-configuration-is-not-a-valid-configuration-swift, but I'm uncomfortable with the solution of recreating my project without identifying a cause that I can avoid in the future.

Answered by DTS Engineer in 712457022

Hello,

Looking at the code in that post you linked to, they are setting a selectionLimit of 1.

The header comments for the preselectedAssetIdentifiers property (in PHPicker.h) says:

preselectedAssetIdentifiers should be an empty array if selectionLimit is 1 or photoLibrary is not specified.

So, at least in their case, it is likely that the selectionLimit of 1 is the issue, are you also setting a selectionLimit of 1?

Accepted Answer

Hello,

Looking at the code in that post you linked to, they are setting a selectionLimit of 1.

The header comments for the preselectedAssetIdentifiers property (in PHPicker.h) says:

preselectedAssetIdentifiers should be an empty array if selectionLimit is 1 or photoLibrary is not specified.

So, at least in their case, it is likely that the selectionLimit of 1 is the issue, are you also setting a selectionLimit of 1?

You don't need to request any library access to use preselectedAssetIdentifiers.

I don't have enough information to help you identify the problem, but the cause could be similar to https://developer.apple.com/forums/thread/664970?answerId=646377022#646377022. Please double check if you have some code or 3rd party dependencies modifying system classes, like NSArray or NSObject.

I'm having a similar issue even with selectionLimit > 1.

The issue seems to be that the PickerResults itemIdentifers don't have the UTTypes for thepreselectedAssetIdentifiers that are passed in

// For an id that was passed into `preselectedAssetIdentifiers`
<PUPhotosFileProviderItemProvider: 0x60000306d3b0> {types = (
)} 

// For a newly selected photo
<PUPhotosFileProviderItemProvider: 0x60000306de60> {types = (
    "public.jpeg",
    "com.apple.private.photos.thumbnail.standard",
    "com.apple.private.photos.thumbnail.low"
)}

Haven't found a solution but to remove the preselectedAssetIdentifiers

Hope this helps Killian

PHPickerViewController crashes when configuration has preselectedAssetIdentifiers
 
 
Q