Randall Wang Randall Wang - 1 month ago 25
Objective-C Question

Xcode 8 UIImagePickerController frozen

I just run into this problem. I can call UIImagePickerController as usual but when I pick an Image(taking a photo or photo library), the "use photo" button and "retake" button don't work, and the UI just freezes.

I have done some debugging and found the code won't get into the delegate method.

I didn't change any code about UIImagePickerController. Everything works just fine before. So I'm wondering why this happened and how to fix this bug?

Thanks a lot!

Here is the code :

UIImagePickerController * imgPicker = [[UIImagePickerController alloc] init];
[imgPicker setDelegate:self]
[imgPicker setAllowsEditing:YES];
[imgPicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self.navigationController presentViewController:imgPicker animated:YES completion:^{

}];

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo {

[self dismissViewControllerAnimated:YES completion:^{
}];
}

Answer

I figure this out.This is caused by using the wrong delegate method.the one I was using has been DEPRECATED.

We should use this one

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info;

and the image information is in the info dictionary.You can get the image in this way

UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];