Hey all, a question about PhotosUI. I see a weird behaviour when the completion handler for presentLimitedLibraryPicker
gets called twice. The first one returns only one identifier, and the second one comes with all the selected photos.
Here is the sample code
import UIKit
import PhotosUI
class ViewController: UIViewController {
let button = UIButton(type: .system)
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
view.addSubview(button)
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in }
button.frame = CGRect(origin: view.center, size: .init(width: 200, height: 50))
button.center = view.center
button.setTitle("Open Picker", for: .normal)
button.addAction(UIAction(handler: { _ in
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self) { ids in
print(ids)
}
}), for: .touchUpInside)
}
}
After selecting 3 photos the output in the console will be like
["CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001"] //1 item
["CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001", "ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED/L0/001", "99D53A1F-FEEF-40E1-8BB3-7DD55A43C8B7/L0/001"] // 3 items