Interesting problem I found here. I am trying to load in pre-selected identifiers via preselectedAssetIdentifiers, which is working correctly. Essentially, I am letting my users edit photos, and as they edit one and move to the next, that image is being uploaded. So, i am swapping out the PHPickerViewController from the root of the navigation controller with only the remaining selected images, so that if the user cancels the editing, they go back to the picker with only the unedited images selected still.
if shouldResetSelectionLimit, let images = self.images, !images.isEmpty {
self.config.selectionLimit = images.count + 1
if #available(iOS 15.0, *), var order = self.order {
order.append(self.currentId ?? "")
order.reverse()
self.config.preselectedAssetIdentifiers = order
}
} else {
if #available(iOS 15.0, *) {
self.config.preselectedAssetIdentifiers = []
}
if self.currentImage != nil {
self.config.selectionLimit = 1
}
}
let pickerViewController = PHPickerViewController(configuration: config)
pickerViewController.delegate = self
The issue I am having however, is the behavior of preselectedAssetIdentifiers
according to the documentation, "Results include all preselected identifiers when canceling the picker". Now, i had assumed this remained true only while those were selected, but as it turns out, even if the user then proceeds to deselect these items, hitting cancel will not cancel.
I can no longer properly detect a cancel action, since both the cancel and the done action call the same delegate function (see PHPickerViewControllerDelegate). In this case, if the user unselects everything or doesn't cancel is always sending the identifiers. This simply just doesn't make sense, particularly for the case where the user unselects everything. Done is now ALSO sending every identifier unless the users deselects everything.
How do people get around this odd behavior? I can't seem to find a way to do this well