I have a method which sends out a request and has a delegate responder. The method is being called by a KVO responder. The code works fine when I call it from viewDidLoad, but when I make the request from the KVO method, it doesn't trigger the delegate method.
here is my KVO responder:
//observe app delegates userdata to check for when user data is available or data is changed
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if ([keyPath isEqualToString:@"userData"] )
{
//goto facebook logic
[self FBFriendSuggester];
}
}
and the method it calls:
-(void)FBFriendSuggester
{
NSDictionary * fb_credentials = nil;
if([prefs objectForKey:@"facebookCredentials"])
{
fb_credentials = [prefs objectForKey:@"facebookCredentials"];
if ([fb_credentials objectForKey:@"expiry"] && [fb_credentials objectForKey:@"fbtoken"]) {
NSLog(@"found stored Facebook credentials.");
ApplicationDelegate.facebook.accessToken = [fb_credentials objectForKey:@"fbtoken"];
ApplicationDelegate.facebook.expirationDate = [fb_credentials objectForKey:@"expiry"];
}
}
if ([ApplicationDelegate.facebook isSessionValid]) {
printf("_valid facebook\n");
[ApplicationDelegate.facebook requestWithGraphPath:@"me/friends" andDelegate:self];
}else
printf("_invalid facebook\n");
}
and the delegate method:
- (void)request:(FBRequest *)request didLoad:(id)result{
NSLog(@"result2:%@",result);
NSDictionary * rawObject = result;
NSArray * dataArray = [rawObject objectForKey:@"data"];
for (NSDictionary * f in dataArray) {
[friends addObject:[[KNSelectorItem alloc] initWithDisplayValue:[f objectForKey:@"name"]
selectValue:[f objectForKey:@"id"]
imageUrl:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=square", [f objectForKey:@"id"]]]];
}
[friends sortUsingSelector:@selector(compareByDisplayValue:)];
[self pickerPopup:self];
}
the delegate method doesn't get called in this scenario, but it does work fine when i call -(void)FBFriendSuggester directly from the controller. I don't know what to do, i tried setting a notification to respond in hopes that it would trigger the delegate, but that didn't work either.