I'm experiencing the next issue:
I have 3 classes that are taking data from Facebook API and are communicating through delegating. First class takes my friends, then for each friend 2nd class calls friend's events, return them and then for each friend's event, 3rd class calls event's ID to get full event infos. This is where the issue comes in, after calling 3rd class, the fb request api gets executed (requestLoading function gets started) but it doesn't wait in that class to get reply but just jumps out of the class.
Here is the code:
I have 3 classes that are taking data from Facebook API and are communicating through delegating. First class takes my friends, then for each friend 2nd class calls friend's events, return them and then for each friend's event, 3rd class calls event's ID to get full event infos. This is where the issue comes in, after calling 3rd class, the fb request api gets executed (requestLoading function gets started) but it doesn't wait in that class to get reply but just jumps out of the class.
Here is the code:
Code:
// Class 1:
// calling friends in first class
- (void) callFriendData
{
PicShowAppDelegate* appDelegate = (PicShowAppDelegate*)[[UIApplication sharedApplication] delegate];
Facebook *facebook = appDelegate.facebook;
[facebook requestWithGraphPath:@"me/friends" andDelegate:self];
}
// receiving friends + calling friend class for each friend in which we will call events
- (void)request:(FBRequest *)request didLoad:(id)result {
NSMutableArray *data = [result objectForKey:@"data"];
NSMutableArray *tmpFriendID = [data valueForKey:@"id"];
NSMutableArray *tmpFriendName = [data valueForKey:@"name"];
for(int i=0;i<[tmpFriendID count];i++)
{
FBFriend *fbFriend = [[FBFriend alloc]init];
[fbFriend setDelegate:self];
fbFriend.friendID = [tmpFriendID objectAtIndex:i];
fbFriend.friendName = [tmpFriendName objectAtIndex:i];
[fbFriend takeEvents];
[friendDataArray addObject:fbFriend];
[fbFriend release];
}
}
// class 2, friend, here I call events
- (void) takeEvents
{
PicShowAppDelegate* appDelegate = (PicShowAppDelegate*)[[UIApplication sharedApplication] delegate];
Facebook *facebook = appDelegate.facebook;
[facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/events",self.friendID] andDelegate:self];
}
// receiving events for certain user
- (void)request:(FBRequest *)request didLoad:(id)result {
....
// sending events back to 1st class
[[self delegate] eventsTaken:eventIDs fromFriendID:self.friendID];
}
// first class receives events for certain user, finds where he has to put them, and does so and then calls 3rd class, event
- (void) eventsTaken: (NSArray *)idEvents fromFriendID: (NSString*) idFrenda
{
for(int i=0;i<[friendDataArray count];i++)
if([[[friendDataArray objectAtIndex:i] valueForKey:@"friendID"] isEqual:idFrenda])
for(int j=0;j<[idEvents count];j++)
{
Event *event = [[Event alloc] init];
event.eventID=[idEvents objectAtIndex:j];
[event takeEvent];
[event release];
}
}
// 3rd class, event
-(void) takeEvent
{
PicShowAppDelegate* appDelegate = (PicShowAppDelegate*)[[UIApplication sharedApplication] delegate];
Facebook *facebook = appDelegate.facebook;
[facebook requestWithGraphPath:[NSString stringWithFormat:@"%@",self.eventID] andDelegate:self];
}
// HERE IT FAILS, THIS NEVER GETS CALLED -> ??
- (void)request:(FBRequest *)request didLoad:(id)result {
....
}