How can I replace deprecated method dispatch_get_current_queue() from ios5 to ios6 in iphone? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-03 09:21:06

It depends what you need to achieve with this call.
Apple states that it should be used for debugging anyway.

Perhaps the queue does not matter (as you just need a background queue) so get a global queue with specific priority (dispatch_get_global_queue(dispatch_queue_priority_t priority, unsigned long flags);)

OR,

If you do need to execute some pieces of code in the same queue , create a queue, retain it and dispatch all your tasks there.

How about using NSOperationQueue?

-(void) doSomeThing:(void (^)(BOOL success)) completionHandler
{
    NSOperationQueue* callbackQueue = [NSOperationQueue currentQueue];
    if(!callbackQueue) {
        callbackQueue = [NSOperationQueue mainQueue];
    }
    dispatch_async(...,^{
         // do heavyweight stuff here
         // then call completionHandler
         if(completionHandler) {
             [callbackQueue addOperationWithBlock:^{
                 completionHandler(...);
             }];
         }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!