0

Problem-> i just wanna fetch scores of friends not on main queue but on different queue and in that queue I also called login, openSession methods for sign in. I wanna try to fetch scores

STEP 1 -> -(void)requestcallerWithQueue in this method i m trying to fetch score inside queue created by me (not main queue) then FBRequestConnection startWithGraphPath: method call in FBRequestConnection startWithGraphPath: NOT RESPONDING.

STEP 2 -> -(void)requestcallerWithoutQueue in this method i m trying to fetch score inside queue created by me (not main queue) then FBRequestConnection startWithGraphPath: method call in FBRequestConnection startWithGraphPath: RESPONDING

          **CODE IS BELOW FOR REFERENCE**


-(void)fetchscoreWithCallback:(void (^)(NSDictionary*))callback
 {

    NSMutableDictionary* params =   [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 [NSString stringWithFormat:@"%ld", (long)10],     @"score",
                                 nil];

// [NSString stringWithFormat:@"%llu/scores", lintFBFriendId]
    [FBRequestConnection startWithGraphPath:@"245526345633359/scores"
                             parameters:params
                             HTTPMethod:@"GET"
                      completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
 {
     NSLog(@"result->%@",result);


 }

}

NOT WORKING

-(void)requestcallerWithQueue
{

    dispatch_queue_t some_queue = dispatch_queue_create("some.queue.name", NULL);
    dispatch_async(some_queue, 
   ^{
       [self  fetchscoreWithCallback:callback];
    }];

}

WORKING

-(void)requestcallerWithoutQueue
{

       [self  fetchscoreWithCallback:callback];

}
UA_PPS
  • 29
  • 9

1 Answers1

0

FBRequestConnection uses NSURLConnection which by default requires the calling thread to have a run loop. For non main threads, you have to manage the run loop yourself or dispatch the work back to the main queue. For some resources, check out:

http://coc24hours.blogspot.com/2012/01/using-nsrunloop-and-nsurlconnection.html

NSURLConnection needs a NSRunLoop to execute?

http://iosdevelopmentjournal.com/blog/2013/01/27/running-network-requests-in-the-background/

Community
  • 1
  • 1
Chris Pan
  • 1,903
  • 14
  • 16