ios - Objective C - 调用 dispatch_async 显示错误
<p><p>我正在使用 dispatch_async 在其他方面做一些事情。</p>
<pre><code>dispatch_queue_t backgroundQueue;
</code></pre>
<p>在viewDidLoad中:</p>
<pre><code>- (void)viewDidLoad
{
;
// Do any additional setup after loading the view.
backgroundQueue = dispatch_queue_create("dispatchName", NULL);
}
</code></pre>
<p>使用它:</p>
<pre><code>dispatch_async(backgroundQueue, ^
{
// Do something...
});
</code></pre>
<p>在我再次调用此方法之前一切正常。
该应用程序因错误而崩溃:</p>
<pre><code>2014-09-29 11:34:10.626 hELLO *** Assertion failure in -, /SourceCache/UIKit_Sim/UIKit-3318/Keyboard/UIKeyboardTaskQueue.m:374
2014-09-29 11:34:10.628 hELLO *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '- may only be called from the main thread.'
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您正在尝试执行进程,该进程只能在主线程中执行。
将代码放入</p>
<pre><code>dispatch_async(dispatch_get_main_queue(), ^{
})
</code></pre></p>
<p style="font-size: 20px;">关于ios - Objective C - 调用 dispatch_async 显示错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26095672/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26095672/
</a>
</p>
页:
[1]