iOS公共基础

iOS-相机拍照崩溃

2016-08-23  本文已影响122人  FlyElephant

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

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
    if (granted) {
        [self presentViewController:self.imagePickerController animated:YES completion:^{}];
    }
}];`</code></pre>

在回调里面进行present操作,Block块中present不是在主线程执行,会报错,需要在主线程进行present操作:
<pre><code>[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if (granted) { dispatch_async(dispatch_get_main_queue(), ^{ [self presentViewController:self.imagePickerController animated:YES completion:^{}] }); } }];</code></pre>

简书-FlyElephant 参考资料

上一篇 下一篇

猜你喜欢

热点阅读