UIImagePickerController not presenting in iOS 8

后端 未结 12 1549
借酒劲吻你
借酒劲吻你 2020-12-12 16:39

Is anyone else having an issue with UIImagePickerController in iOS 8? The method below works perfectly well in iOS 7 on an iPad, but I get the following error

相关标签:
12条回答
  • 2020-12-12 16:41
    UIImagePickerController *imagePickerController= [[UIImagePickerController alloc] init];
    [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    
    // image picker needs a delegate so we can respond to its messages
    [imagePickerController setDelegate:self];
    self.shouldCallViewWillAppear = NO;
    
    if(IS_IOS8)
    {
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            // Place image picker on the screen
            [self presentViewController:imagePickerController animated:YES completion:nil];
        }];
    }
    else
    {
        [self presentViewController:imagePickerController animated:YES completion:nil];
    }
    
    0 讨论(0)
  • 2020-12-12 16:42

    I was facing the same problem in iOS 8. Then I saw the change log of the latest update to iOS i.e. 8.0.2 on the device.

    It is mentioned in this update that_

    "Fixes an issue that prevented some apps from accessing photos from Photo Library"

    So test your app using XCode 6 on device with iOS 8.0.2 version it will work fine Don't test it on iOS 8.0 simulator.

    This helped me, hope the same for you.

    Screen-shot of iOS 8.0.2 Update change log

    0 讨论(0)
  • 2020-12-12 16:46

    All you need to do is dismiss already presented ViewController:

    if (self.presentedViewController) {
        [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
    }
    
    [self openPhotoPicker:sourceType];
    

    If it still produces error, put openPhotoPicker: to completion handler

    0 讨论(0)
  • 2020-12-12 16:49

    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.

    0 讨论(0)
  • 2020-12-12 16:56

    I simply did this:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,
                                             (unsigned long)NULL), ^(void) {
    
        [self retractActivePopover];
    
        dispatch_async(dispatch_get_main_queue(), ^ {
    
            _activePopover=imagePickerPopover;
    
            UIBarButtonItem *callingButton = (UIBarButtonItem*) sender;
    
            [imagePickerPopover presentPopoverFromBarButtonItem:callingButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
        });
    
    });
    
    0 讨论(0)
  • 2020-12-12 16:59

    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.

    0 讨论(0)
提交回复
热议问题