iOS-相机拍照崩溃

最近在使用系统拍照,只要一点击拍照就崩溃,不稳定复现,最终抓到Log如下:[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.
最终定位到代码:

    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
        if (granted) {
            [self presentViewController:self.imagePickerController animated:YES completion:^{}];
        }
    }];

在回调里面进行present操作,Block块中present不是在主线程执行,会报错,需要在主线程进行present操作:

    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
        if (granted) {
            dispatch_async(dispatch_get_main_queue(), ^{
                    [self presentViewController:self.imagePickerController animated:YES completion:^{}]
            });
        }
    }];

简书-FlyElephant 参考资料

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容