0

I am making a call to a service from a main thread, and getting the results. But when the same call is made from background, i am not getting results. Any thoughts?

Here is my code :

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];
    });

In my class PathRequest, i have defined delegate methods for handling server response

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

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

1 回答 1

0

运行运行循环,以便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];
});
于 2013-04-03T06:35:32.653 回答