I have a class which I am using to interact with Facebook in Objective C for my iPhone application.
GWFacebook.h
@interface GWFacebook : Facebook <FBRequestDelegate>
{
bool query_running;
NSArray* query_result;
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error;
- (void)request:(FBRequest *)request didLoad:(id)result;
- (void)LogIn;
- (NSArray*)getAllFriends;
@end
GWFacebook.m
#import "GWFacebook.h"
@implementation GWFacebook
- (void)request:(FBRequest *)request didLoad:(id)result
{
query_result = result;
query_running = false;
}
- (NSArray*)getAllFriends
{
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"SELECT first_name, last_name, uid, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY mutual_friend_count desc",@"query",nil];
query_running = true;
bool localbool = true;
[self requestWithMethodName: @"fql.query" andParams: params andHttpMethod: @"POST" andDelegate: self];
while(localbool)
localbool = query_running;
return query_result;
}
@end
Basically the function getAllFriends makes a fb request and sets this object as the facebook request delegate. The function request didLoad of the delegate (self) is then called and uses a variable to pass the data back to the getAllFriends function, which then returns it to whatever called it.
The long and short of it is that im trying to use a while loop to stall the function until it receives a response. In debugging, its clear that the request didload function is never called by the facebook object. It is called when I remove the while loop ... thus the data request is successful and the while loop is the problem.
Im wondering if there is a way to stall a function until the data is received...Im probably doing something very silly so I need some help!
Thanks