当前位置: 首页 > 工具软件 > Photo Picker+ > 使用案例 >

使用PHAsset在新的Photo Picker PHPicker

闻人河
2023-12-01
import UIKit
import PhotosUI
class PhotoKitPickerViewController: UIViewController, PHPickerViewControllerDelegate {
		@IBAction func presentPicker(_ sender: Any) {
				let photoLibrary = PHPhotoLibrary.shared()
				let configuration = PHPickerConfiguration(photoLibrary: photoLibrary)
				let picker = PHPickerViewController(configuration: configuration)
				picker.delegate = self
				present(picker, animated: true)
		}
		
		func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
				picker.dismiss(animated: true)
				
				let identifiers = results.compactMap(\.assetIdentifier)
				let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: nil)
				
				// TODO: Do something with the fetch result if you have Photos Library access
		}
}
 类似资料: