在主线程

时间:2015-05-28 22:23:53

标签: ios objective-c iphone

我需要在后台线程上运行块,但是一旦它进入块,它就会将后台线程转换为主线程。

代码:

dispatch_queue_priority_t priority = DISPATCH_QUEUE_PRIORITY_BACKGROUND;

    dispatch_async(dispatch_get_global_queue(priority, 0), ^(void){
        [self getLinks:completion];
        [self getPhoneNumbers:completion];
        [self getUrls:completion];
    });

- (void)getLinks:(links)completion
{
    __weak typeof(self) weakSelf = self;

    "Check current thread here using po dispatch_get_current_queue()"
//Result: <OS_dispatch_queue_root: com.apple.root.background-qos[0x10eaa5a00] = { xrefcnt = 0x80000000, refcnt = 0x80000000, suspend_cnt = 0x0, locked = 1, target = [0x0], width = 0x7fff, running = 0x1, barrier = 0 }>

    [MainLinks retrieveLinksWithSuccess:^(response *LinksResponse){

  "Check current thread here using po dispatch_get_current_queue()"
//Result: <OS_dispatch_queue: com.apple.main-thread[0x10eaa5780] = { xrefcnt = 0x80000000, refcnt = 0x80000000, suspend_cnt = 0x0, locked = 1, , thread = 0x607 >

        __strong typeof(self) strongSelf = weakSelf;
        strongSelf.clientLinks = [LinksResponse getClintLinks];
        [strongSelf processFiles];
        [strongSelf finishLinksCompletion:completion];
    } failure:^(NSError *error) {

    }];
}

我希望我在block中调用的方法也想在后台运行,我不确定我做错了什么,这使得它们在主线程上推送它。

retrieveLinksWithSuccess代码:

 [self getDataUsingEndpoint:@"links"
                        tokens:@{@"linkid" : AuthenticationService.sharedInstance.userid.urlEncode ?: @""}
                    parameters:@{@"site" : @"coupon"}
                       success:success
                       failure:failure];

0 个答案:

没有答案