为什么UIAlertController不允许相机在iOS 12上启动?

问题描述

我遇到的问题是,当点击缩略图时,此操作有效。

-(IBAction)thumbnailTapped:(UIGestureRecognizer *)tap
{
    if (_customItem.file.isEmpty)
    {
        [self openCamera];   // opens camera if no image is present
    }
    else
    {
        _isTransitioningToFullViewOrCamera = true;
        [self performSegueWithIdentifier:@"CustomFileViewFromItem" sender:self];  // if file is present then it shows the picture blown up.
    }
}

,以下代码称为:

-(void) openCamera
{
    _isTransitioningToFullViewOrCamera = true;
    Nsstring *ext = _customItem.file ? _customItem.file.ext : JpgExt;
    if ([CustomCameraController isCameraAvailableForExt:ext forViewController:self])
        [CustomCameraController launchCameraForExt:ext forViewController:self];
}

但是从UIAlertAction调用时,相机根本无法打开。

UIAlertController *actionSheet;
actionSheet = [UIAlertController alertControllerWithTitle:@"Select an action:" message:nil preferredStyle:UIAlertControllerStyleAlert];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {      
    // Cancel button tappped.
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Replace" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {              
    self dismissViewControllerAnimated:YES completion:^{
    }];
    [self openCamera];
                        
}]];

// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];

如果[self openCamera]是否位于补全代码块中,则不会更改任何内容

我想知道是否有人对此有任何经验;当UIAlertController不存在时(例如单击),[self openCamera]打开相机,您可以拍照。但是,在显示UIAlertController之后调用该摄像头时,它不会打开,并且会静地失败。

解决方法

“问,您将收到”

当您连续数天无人碰壁时,应该有一个格言,那就是问一个问题,然后自己找到答案。

答案是发表评论

:styles

因为它关闭了包含//self dismissViewControllerAnimated:YES completion:^{ // }]; 函数的视图。

我不敢相信直到现在我才意识到这一点。

任务已经完成! :)