我正在从主线程调用服务并获取结果。但是当从后台进行同样的调用时,我没有得到结果。有什么想法吗?
这是我的代码:
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 {
}
答案 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];
});