2

I have a problem where the delegate of UIImagePickerController not being called when presented with sourceType = UIImagePickerControllerSourceTypePhotoLibrary.

Oddly enough, it works perfectly fine in camera mode.

Interface declaration:

@interface ChatVC : UIViewController <UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>

And in implementation:

- (void)takePhotoAction {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController* imgPickerController = [[UIImagePickerController alloc] init];
        imgPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        imgPickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
        imgPickerController.allowsEditing = YES;

        imgPickerController.delegate = self;

        [self presentViewController:imgPickerController animated:YES completion:nil];
    }
}

- (void)choosePhotoFromLibraryAction {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController* imgPickerController = [[UIImagePickerController alloc] init];
        imgPickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imgPickerController.allowsEditing = YES;

        imgPickerController.delegate = self;

        [self presentViewController:imgPickerController animated:YES completion:nil];
    }
}

And here's the delegate method implementation in the same view controller:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary<NSString *,id> *)editingInfo {
    NSLog(@"Image Picker Controller Picked Image - Deprecated");
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSLog(@"Image Picker Controller Picked Image");    
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    NSLog(@"Image Picker Controller Cancelled");
    [picker dismissViewControllerAnimated:YES completion:nil];
}

When opened in camera mode, everything works just fine, and I can see the appropriate delegate methods being called.

But when opened in photo library mode and I choose a photo, nothing happens and no delegate method is called. However, I can see -imagePickerControllerDidCancel: delegate method being called when I tap on Cancel button.

I even suspected memory warning somehow invalidates the delegate, but it was not the case here.

Please someone help me figure this out.

Thanks in advance!

jayden
  • 21
  • 1
  • What version of Xcode, iOS and what device are you testing this with? – rmaddy Nov 12 '15 at 04:26
  • @rmaddy Thanks for your reply. I've tested with iOS 8 & 9, on simulator & device. Xcode version 7.1. – jayden Nov 12 '15 at 04:48
  • 1
    With the code you attached, it worked perfectly. Called `imagePickerController:didFinishPickingMediaWithInfo:`. Tested on iO8.4/9.1 simulator. – Ryan Nov 12 '15 at 05:46
  • @trick14 yeah, I know. it supposed to be working perfectly. but the problem is, it's not working as expected and wanted to know what could be possibly wrong in any other parts of the app? any idea? – jayden Nov 12 '15 at 05:51
  • Can you share the project to look into? I'm sure that the source code you appended has no problem. – Ryan Nov 12 '15 at 05:52
  • @trick14 thanks for your confirmation. I'm afraid I can't disclose it as I'm currently working on a private project, but what specific part of the codebase are you interested in? any clues about what could lead to this bug-like behaviour? i'm stuck like for a week by now. :( – jayden Nov 12 '15 at 16:56
  • @jayden I couldn't find anything the code above. I just copied and pasted to a new project and worked perfectly. The problem might be in somewhere else. – Ryan Nov 13 '15 at 01:24
  • @trick14 could you tell me what specific parts of the app could be responsible for that? it really makes me crazzzzy. Thanks! – jayden Dec 14 '15 at 19:13

0 Answers0