read

Apple’s Camera Programming Guide for taking pictures and movies is outdated.

It was last updated on 2012-07-17 (as of writing), and this doesn’t take into account of new stuff eg. iOS 7 changes and ARC

In iOS 5, the behaviour of UIViewController parentViewController has changed.

Prior to iOS 5.0, if a view did not have a parent view controller and was being presented, the presenting view controller would be returned. On iOS 5, this behavior no longer occurs. Instead, use the presentingViewController property to access the presenting view controller.

Which means when you dismiss the picker, the parentViewController could be nil, and hence it will not dismiss as you expected.

This is my updated source code for responding to the user tapping Cancel.

- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker {
    UIViewController *dismissingController = nil;
    if ([picker respondsToSelector:@selector(presentingViewController)])
        dismissingController = picker.presentingViewController;
    else
        dismissingController = picker.parentViewController;

    // Since dismissModalViewControllerAnimated is deprecated in iOS 6..
    if ([dismissingController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]){
        [dismissingController dismissViewControllerAnimated:YES completion:nil];
    } else {
        [dismissingController dismissModalViewControllerAnimated:YES];
    }
}

I also dropped [picker release] since using ARC.

Similarly, replace the code for dismissing when a photo/video is selected.


Image

@samwize

¯\_(ツ)_/¯

Back to Home