PHPickerConfiguration will produce wrong ordering sometimes during multi selection.

We notice PHPickerConfiguration will produce wrong ordering sometimes, during multi selection.

Our app is targeting iOS 15, and the test is run on simulator iOS 15.5

Here the video to demonstrate the issue

https://youtu.be/RrhqFuB2kqs

Please note that, the standing cat picture suppose to be the 4th order.

By looking at the console and UI outcome, it is mistakenly returned as 3rd order.

Here's the code which show

func chooseImage() {
    var configuration = PHPickerConfiguration()
    
    configuration.selectionLimit = 0
    
    // https://developer.apple.com/documentation/photokit/phpickerconfiguration/selection
    configuration.selection = .ordered
    
    // GIF exclusion is still not supported - https://developer.apple.com/forums/thread/687415
    configuration.filter = .images
    let picker = PHPickerViewController(configuration: configuration)
    picker.delegate = self
    present(picker, animated: true)
}

and here's the code which prints out the ordering of images.

extension NewNoteViewController: PHPickerViewControllerDelegate {
    func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
        picker.dismiss(animated: true)
        guard !results.isEmpty else { return }
        
        var displayErrorOnce = false
        
        for result in results {
            result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.image.identifier) { [weak self] (url, error) in
                precondition(!Thread.isMainThread)
                
                guard let self = self else { return }
                guard let url = url else { return }

                print(">>>> url \(url)")
                
                // ...
            }
        }
    }
}

This problem happens randomly.

May I know, is there any workaround for this issue?

Thank you.

PHPickerConfiguration will produce wrong ordering sometimes during multi selection.
 
 
Q