ORStudios
ORStudios

Reputation: 3233

IOS 10 UIImagePickerController Delegate Not Being Called

I have setup the following to select an image whilst using an IPad. The problem is that the delegate never seems to get called. I've placed breakpoints in but they are never activated.

.H

@interface HomeViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

.M

- (IBAction)loadImage:(id)sender {

self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.allowsEditing = NO;
self.imagePickerController.delegate = self;

[self presentViewController:self.imagePickerController animated:YES completion:nil];

}

// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

//You can retrieve the actual UIImage
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
//Or you can get the image url from AssetsLibrary
NSURL *path = [info valueForKey:UIImagePickerControllerReferenceURL];

[picker dismissViewControllerAnimated:YES completion:nil];
}

Can anyone see the issue?

Thanks

Upvotes: 1

Views: 1068

Answers (2)

PKCLsoft
PKCLsoft

Reputation: 1358

I had a similar issue and it turned out that the picker was being garbage collected as soon as the image was picked, so the delegate wasn't called.

I needed to ensure that a strong reference to the picker was made before presenting it.

Once that was done, it worked fine.

Upvotes: 0

Mistrx丶
Mistrx丶

Reputation: 267

if you used Xcode8 to run the project, please check the project's info.plist, make sure there is a key for "Privacy Photo library usage".

your code is right, maybe the problem is the info.plist.

Upvotes: 1

Related Questions