我正在使用dispatch_async在其他方面做点什么。
dispatch_queue_t backgroundQueue;
在viewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
backgroundQueue = dispatch_queue_create("dispatchName", NULL);
}
使用它:
dispatch_async(backgroundQueue, ^
{
// Do something...
});
在我再次调用此方法之前一切正常。 该应用程序很容易出错:
2014-09-29 11:34:10.626 hELLO[2785:389790] *** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /SourceCache/UIKit_Sim/UIKit-3318/Keyboard/UIKeyboardTaskQueue.m:374
2014-09-29 11:34:10.628 hELLO[2785:389790] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
答案 0 :(得分:4)
您正在尝试执行进程,该进程只能在主线程中执行。 将代码放入
dispatch_async(dispatch_get_main_queue(), ^{
})