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.

Accepted Reply

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?

  • I'm not setting a selection limit, but 1 is the default, so I guess this is my issue. My use case is that the user can only select one photo, but if the user chooses to change the photo I was hoping that preselecting the one they chose before would help them to jump back in where they left off.

    The bigger problem is that this requirement is unmentioned in the online docs. It would be great to see this page updated to reflect that requirement: https://developer.apple.com/documentation/photokit/phpickerconfiguration

Add a Comment

Replies

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?

  • I'm not setting a selection limit, but 1 is the default, so I guess this is my issue. My use case is that the user can only select one photo, but if the user chooses to change the photo I was hoping that preselecting the one they chose before would help them to jump back in where they left off.

    The bigger problem is that this requirement is unmentioned in the online docs. It would be great to see this page updated to reflect that requirement: https://developer.apple.com/documentation/photokit/phpickerconfiguration

Add a Comment

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.

  • Thanks for the reply. That issue is not related to mine.

Add a Comment

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