Good thing I'm new to threads, so I have this question. I'm trying to get friends info from Facebook and I don't want to do this in the main thread. but for some reason, when the request is not in the main thread, callback is never called, and I donβt know why!
I have an array with all the IDs from my friends and loop through this array and create an object of my custom class Friend (which receives all the necessary information) with each ID. I am adding this object to an array. This friend object makes a request to Facebook and processes the response to get the data I need.
here is the code:
dispatch_async(dispatch_get_global_queue(0, 0), ^(void) { [self getFBFriendsInfo]; }); -(void)getFBFriendsInfo{ if (friendsInfoArray) { [friendsInfoArray removeAllObjects]; } else{ friendsInfoArray =[[NSMutableArray alloc]init]; } for (int i=0; i<[UDID count]; i++) { NSString *udid = [UDID objectAtIndex:i]; FriendsInfo *friend =[[FriendsInfo alloc] initWithFacebook:facebook andUdid:udid]; [friendsInfoArray addObject:friend]; [friend release]; } dispatch_async(dispatch_get_main_queue(), ^(void) { [delegate friendsInfosAvailable:friendsInfoArray]; });
}
and in my custom class I do this:
[facebook requestWithGraphPath:udid andDelegate:self]
with this, the callback is never called! only if I make a request in the main thread does it work:
dispatch_async(dispatch_get_main_queue(), ^(void) { [facebook requestWithGraphPath:udid andDelegate:self]; });
source share