[iOS] PHPickerViewController เครื่องมือสำหรับหยิบรูปจาก Photo Library ของใหม่บน iOS 14+
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2sj6MW0c2lxoS_asRbCFKCyGAlxLG242XT4eNqfbP1WDYxXNUij-QpU8GxLdRboHdicCm8neAM7Bnc85xFRscNDHg-Dp-tJfj7vOdTu20jyido-LNXOVAxux7AMv8LWRUSzRaq7uCwB6lYNWuu6XOIlZ3VkM10MdotvrbsmnX4wTCqPAk-AU0TnMO/s320/Simulator%20Screen%20Shot%20-%20iPhone%20SE%20(3rd%20generation)%20-%202022-08-08%20at%2015.33.58.png)
PHPickerViewController เป็น class สำหรับเรียกใช้งาน Photo Library ซึ่งมีความสามารถเพิ่มเติมจาก UIImagePickerController ที่เป็นของเดิมที่น่าจะคุ้นเคยกันอยู่แล้ว สิ่งที่เหนือกว่าของ PHPickerViewController รองรับการเลือกหลายไฟล์ (Muli-selection) รองรับ livePhoto เป็นการทำงานแบบ async ไม่มีการขอ permission การใช้งานก็ไม่ได้ยุ่งยากมากมายไปกว่ากันซะเท่าไร import PhotosUI ตั้งค่าและเรียกใช้งาน PHPickerViewController var configuration = PHPickerConfiguration() configuration.filter = .any(of: [.images, .livePhotos, .videos]) configuration.selectionLimit = 2 let picker = PHPickerViewController(configuration: configuration) picker.delegate = self self.present(picker, animated: true) และแน่นอนว่า การ handle response จำเป็นจะต้องใช้ delegate ตัวใหม่ เราจะต้อง implement protocol PHPickerViewControllerDelegate ตัวใหม่ด้วย func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { for result in r