Мы выполняем несколько выбора изображения, используя следующий способ. < /p>
Код: Выделить всё
func chooseImage() {
var configuration = PHPickerConfiguration()
configuration.selectionLimit = 0
// https://developer.apple.com/documentation/photokit/phpickerconfiguration/selection
configuration.selection = .ordered
configuration.filter = .images
let picker = PHPickerViewController(configuration: configuration)
picker.delegate = self
present(picker, animated: true)
}
< /code>
Однако мы заметим, что выбираем изображения в следующем порядке < /p>
0.png
1.png
2.png
3.png
4.png
Код: Выделить всё
3.png
2.png
4.png
0.png
1.png
Код: Выделить всё
class NewNoteViewController: UIViewController {
static let theDispatchQueue = DispatchQueue(
label: "com.xxx.yyy.theDispatchQueue",
qos: .userInitiated,
target: nil
)
}
extension NewNoteViewController: PHPickerViewControllerDelegate {
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true)
guard !results.isEmpty else { return }
print(">>>> start the for loop")
for result in results {
result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.image.identifier) { [weak self] (url, error) in
NewNoteViewController.theDispatchQueue.sync {
self?.process(url)
}
}
}
}
private func process(_ url: URL?) {
precondition(!Thread.isMainThread)
guard let url = url else { return }
print(">>>> url \(url)")
...
}
}
Подробнее здесь: https://stackoverflow.com/questions/768 ... -selection
Мобильная версия