Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ALAsset was deprecated - Use PHAsset from Photos Framework

I am retrieving an image using

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) }
      let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
}

I can retrieve the image, also use the image to input to a button background or whatever else I would like, but I cannot seem to retrieve the metadata of the photo. Now, there is a lot of talk on various other locations on the interwebs of using ALAssets and their techniques for image data, BUT, ALAssets is deprecated as of recently. Since my image is not an image that the user just took, but instead an image choosing from the camera roll, I am unable to use :

let metadata = info[UIImagePickerControllerMediaMetaData] as! NSDictionary

So, if anyone could point me in the correct direction as to how to get the metadata of an image that a user just picks from their camera roll, without using ALAssets, it would be greatly appreciated! Thanks!

like image 212
impression7vx Avatar asked Apr 08 '16 05:04

impression7vx


1 Answers

If you want to get images from camera roll then this would help :

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

let imageUrl = info["UIImagePickerControllerReferenceURL"]
let asset = PHAsset.fetchAssetsWithALAssetURLs([imageUrl], options: nil).firstObject as! PHAsset
print("location: " + String(asset.location))
print("Creation Date: " + String(asset.creationDate))

}
like image 171
Muhammad Yawar Ali Avatar answered Sep 22 '22 13:09

Muhammad Yawar Ali