我看过一些相关的问题,但似乎没有人回答这个案例。我想写一个在后台做一些工作的方法。我需要此方法在用于原始方法调用的同一线程/队列上调用完成回调。
- (void)someMethod:(void (^)(BOOL result))completionHandler {
dispatch_queue_t current_queue = // ???
// some setup code here
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
BOOL ok = // some result
// do some long running processing here
dispatch_async(current_queue, ^{
completionHandler(ok);
});
});
这里需要什么魔法咒语,以便在与调用相同的队列或线程上调用完成处理程序sameMethod
?我不想假设主线程。当然dispatch_get_current_queue
是不能使用的。