Post

Replies

Boosts

Views

Activity

Reply to PHPickerViewController & photo metadata
Hi @_mc, Thanks for the kind words! After looking at the link provided by the frameworks engineer and also your comments, I've done a first implementation of PHPickerViewController for our users. So far it seems to be working great, but I'll be sure to keep an eye on iCloud fetches and UI / performance implications. Thanks, alex
Sep ’20
Reply to PHPickerViewController & photo metadata
Hi Frameworks Engineer, Thanks so much! That's exactly what I wanted. Can you explain "can be used to create but not fetch a PHAsset" in detail?. Sure, I can explain but it may have been that since I misunderstood how to use the Picker, I ended up in a workflow that doesn't make any sense. I also should not have said "but not fetch", I should have said "the UIImage for the PHAsset cannot be fetched from PHImageManager." I can see now that this shouldn't be necessary anyways - the image is available from the itemProvider. Here's some sample code: class ViewController: UIViewController {     override func viewDidLoad() {         super.viewDidLoad()         PHPhotoLibrary.requestAuthorization { (status) in             print("\(status)")         }     }          @IBAction func library(sender: UIButton) {         let config = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())         let picker = PHPickerViewController(configuration: config)         picker.delegate = self         self.present(picker, animated: true, completion: nil)     } } extension ViewController: PHPickerViewControllerDelegate {     func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {         dismiss(animated: true, completion: nil)         if let assetId = results.first?.assetIdentifier,            let asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil).firstObject         {             print("asset is \(asset)")             print("asset location is \(asset.location)")             PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: nil, resultHandler: { (image, info) in                 print("requested image is \(image)")             })         }     } } Assuming you have set a value in the Info.plist for Privacy - Photo Library Usage Description, then when you launch the app in the simulator, iOS will present the photo permission alert. Let's say that you choose "Select Photos..." and select only one photo (say one of the waterfall photos). Then, you trigger the IBAction and open the PHPickerViewController. If you choose the waterfall image that you previously chose to share with the app, you will see printed in the logs the asset, the asset location, and the image requested from PHImageManager. However, if you choose one of the photos that you did not choose to share with the app, you will see printed in the logs the asset and the asset location, but the image requested from PHImageManager will be nil and there will be a bunch of errors about Invalid asset uuid for client. Again, I think I only ran into this because I was using the PHPickerViewController incorrectly, so I don't think it's a real problem. Thanks again for your help! Best, alex
Sep ’20