UIImagePickerController not presenting in iOS 8 UIImagePickerController not presenting in iOS 8 ios ios

UIImagePickerController not presenting in iOS 8


I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented while the UIAlertController is being dismissed. I worked around this by delaying the presentation of the UIImagePickerController until the next iteration of the runloop, by doing this:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{    [self openPhotoPicker:sourceType];}];

However, the proper way to fix this is to use the new UIAlertController API on iOS 8 (i.e. use if ([UIAlertController class]) ... to test for it). This is just a workaround if you can't use the new API yet.


I agree with Ben Lings issue detection. I would suggest a simpler solution in case when using UIActionSheet. I simply moved my code that reacts on Action Sheet selection from:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;{// my code}

into:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;  // after animation{// my code}

This way app is guarantied that code will be executed AFTER UIActionSheet animation finishes.

Since UIAlertView has similar delegate method:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  // after animation{// my code}

I suppose that similar solution may apply.


Here is a solution that worked for me

if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0){    [[NSOperationQueue mainQueue] addOperationWithBlock:^{        [self presentViewController:cameraUI animated:NO completion:nil];    }];}else{    [controller presentViewController:cameraUI animated:NO completion:nil];}

Remember to alloc cameraUI

UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

Build and Go!