【问题标题】:Why does the UIAlertController not allow the camera from coming up on iOS 12?为什么 UIAlertController 不允许相机出现在 iOS 12 上?
【发布时间】:2021-02-12 09:52:00
【问题描述】:

我遇到了一个问题,当点击缩略图时,此操作有效。

-(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 出现后调用时,相机将不会打开并静默失败。

【问题讨论】:

    标签: ios objective-c iphone ios12


    【解决方案1】:

    “问,你会收到”

    应该有一句格言,当你连续数日碰壁没有答案,只是提出问题,然后自己找到答案。

    答案是注释掉

    //self dismissViewControllerAnimated:YES completion:^{
    //    }];
    

    因为它关闭了包含 openCamera 函数的视图。

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

    任务完成了! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-04
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2021-05-27
      • 2010-11-01
      相关资源
      最近更新 更多