Setting GPS Data in UIImagePickerControllerMediaMetadata With iOS 8

I’ve been doing some housekeeping on one of the apps I have in the App Store, and I noticed that the image picker was broken when I tested it on the GM version of iOS 8. It took me a while to track it down and, because I couldn’t see the solution on StackOverflow, I thought I’d do a quick posting here.

So the background to this is if you want to add something into the UIImagePickerControllerMediaMetadata dictionary after you have taken a picture, and the classic example is saving back GPS data.

The long and short of it is that you can no longer assign  UIImagePickerControllerMediaMetadata straight to a NSMutableDictionary. My code originally looked like this:

NSMutableDictionary *tmpMetadataDic = [info objectForKey:UIImagePickerControllerMediaMetadata];

which, if I called it, threw an error like this:

[__NSDictionaryI setObject:forKey:] unrecognized selector sent to instance....

The clue is that reference to NSDictionaryI, which means that you’re trying to set something in a non mutable dictionary.

So doing something like this works:

NSDictionary *nonMutytmpMetadataDic = [info objectForKey:UIImagePickerControllerMediaMetadata];    
NSMutableDictionary *tmpMetadataDic = [[NSMutableDictionary alloc] initWithDictionary:nonMutytmpMetadataDic];