Randall Wang
Randall Wang

Reputation: 1037

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:^{
    }];
}

Upvotes: 2

Views: 300

Answers (2)

Ahmed Sahib
Ahmed Sahib

Reputation: 213

From xcode 8 with ios 10 you have to add some key value to the info.plist for accessing the photos using UIImagepicker Controller

Key : Privacy - Photo Library Usage Description
Value : This app requires access to the photo library

Upvotes: 1

Randall Wang
Randall Wang

Reputation: 1037

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"];

Upvotes: 1

Related Questions