简体   繁体   中英

Results coming on main thread, but not on background thread

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 { 
}

Run the run loop so that NSConnection works

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM