info[UIImagePickerControllerPHAsset] in imagePickerController(_:didFinishPickingMediaWithInfo:) returns nil on iOS 11

Originator:hey.hgl
Number:rdar://34404703 Date Originated:
Status: Resolved:
Product:photos Product Version:
Classification: Reproducible:
 
Summary:
I'm unable to retrieve UIImagePickerControllerPHAsset from the info dictionary returned in imagePickerController(_:didFinishPickingMediaWithInfo:). It's always nil. Tested both  on iPhone X simulator in Xcode 9 GM and iOS 11 on iPhone 5s.

I uploaded a test case to demonstrate the issue, check the console, it shouldn't print nil.

I remember it returned nil in previous beta versions, I thought it was going to be fixed, but it's still not working for me in the GM version.

Steps to Reproduce:
Present a UIImagePickerController()
Select a photo 
Access info[UIImagePickerControllerPHAsset] in imagePickerController(_:didFinishPickingMediaWithInfo:)

Expected Results:
a PHAsset object is returned

Actual Results:
nil is returned

Version/Build:
Xcode Version 9.0 (9A235)
macOS 10.13 Beta (17A360a)

Comments

This is not a bug by itself. However, it is poorly explained in the documentation. In order to get the UIImagePickerControllerPHAsset in the info dictionary you need to request photo library authorization first. This is because the asset can contain information other than the image (like the geolocation), so Apple wants to ensure that the user agrees to your app having access to it. Check the PHPhotoLibrary requestAuthorization method documentation on how to use it. Once the user grants authorization, the UIImagePickerControllerPHAsset is populated.

By websupport at Jan. 24, 2019, 12:28 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!