结果来自主线程,但不是后台线程

时间:2013-04-03 06:03:55

标签: iphone ios

我正在从主线程调用服务并获取结果。但是当从后台进行同样的调用时,我没有得到结果。有什么想法吗?

这是我的代码:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
                                             (unsigned long)NULL), ^(void) {
        self.pathRequest = [[PathRequest alloc] initWithUserId:[userInfobase userId]

        self.pathRequest.target = self;
        self.pathRequest.successSelector = @selector(success:);
        self.pathRequest.errorSelector = @selector(failure:);
        [self.pathRequest execute];
    });

在我的类PathRequest中,我已经定义了处理服务器响应的委托方法

 - (void) execute
{    
     [restClient loadData:@"/path"];
}

- (void)restClient: (AFRestClient *) client loadedData: (AFMetaData *) metadata { 
}

1 个答案:

答案 0 :(得分:0)

运行run循环以使NSConnection正常工作

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
                                         (unsigned long)NULL), ^(void) {
    [[NSRunLoop currentRunLoop] run];
    self.pathRequest = [[PathRequest alloc] initWithUserId:[userInfobase userId]

    self.pathRequest.target = self;
    self.pathRequest.successSelector = @selector(success:);
    self.pathRequest.errorSelector = @selector(failure:);
    [self.pathRequest execute];
});