I have seen and read the documents of Apple where they have clearly mentioned about the key UIImagePickerControllerEditedImage. But when I am running my following code, I am not getting that key in the Dictionary. What is the reason behind this?
My Code:
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!)
{
println(info)
//var tempImage:UIImage = info[UIImagePickerControllerOriginalImage] as UIImage
var tempImage:UIImage? = info[UIImagePickerControllerEditedImage] as? UIImage
profileButton.setImage(tempImage, forState: UIControlState(0))
self.dismissViewControllerAnimated(true, completion:nil)
}
println(info) prints:
{
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x178295d60> size {960, 960} orientation 0 scale 1.000000";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=2DDCE06B-6082-4167-A631-B3DF627055DF&ext=JPG";
}
FYI, I am picking image from Library and I tried from Camera also, but this key is still not coming but the other data about image is coming. And I am using iOS8.0 build SDK.
So how can I use UIImagePickerControllerEditedImage
if there is no such key coming in the dictionary.
I found the cause of the issue! Its because of the property "allowsEditing" which was set to false! I have changed that to true and now it is working fine.
Swift 4.2
SWIFT 3.0:
Add
UINavigationControllerDelegate
andUIImagePickerControllerDelegate
You can do it like this.