Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 30, 2011, 01:02 PM   #1
kikovi
macrumors newbie
 
Join Date: Aug 2011
Xcode: requestDidLoad FB Graph API doesn't get loaded

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:
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 {
    ....
    }
kikovi is offline   0 Reply With Quote
Old Aug 30, 2011, 02:19 PM   #2
ianray
macrumors 6502
 
Join Date: Jun 2010
Location: @
Have you used NSLog statements to confirm the program flow?

Have you implemented the following?

Code:
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"request:didReceiveResponse:");
}

- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"request:didFailWithError:%@:%d", error.domain, error.code);
}
The first step in debugging is always to get facts about program flow and error conditions. Hope this helps
__________________
My App Store App: Dashometer -- GPS dashboard, speedometer, and navigation tool
ianray is offline   0 Reply With Quote
Old Sep 1, 2011, 02:00 AM   #3
kikovi
Thread Starter
macrumors newbie
 
Join Date: Aug 2011
Hello, thanks for reply.

Yes I have implanted all those functions and they just don't get called, only requestLoading does. I ve set NSLogs everywhere and still can't identify the issue, this one is a hard one.
kikovi is offline   0 Reply With Quote
Old Sep 1, 2011, 03:20 PM   #4
idelovski
macrumors regular
 
Join Date: Sep 2008
This is wrong:

Code:
   NSMutableArray *data = [result objectForKey:@"data"];
   NSMutableArray *tmpFriendID = [data valueForKey:@"id"];
   NSMutableArray *tmpFriendName = [data valueForKey:@"name"];
In the first line you'll get array of dictionaries, so you need an -objectAtIndex: at some place. Something like this:

Code:
   NSArray       *data = [result objectForKey:@"data"];
   NSDictionary  *person = [data objectAtIndex:0];  // or in a loop
      
   NSString  *name = [person objectForKey:@"name"];
   NSString  *friendId = [person objectForKey:@"id"];
And you need to check everything you get from the server. Use isKindOfClass: on almost anything you get as response and check if it's nil.

Today I had a crash with the code that handles friends icons. My code would receive all the images except one, and then I had a crash. In debugger I found the reason, I got something useless as a result so -imageWithData: returned nil and in the next line I tried to put it into a dictionary so I had a crash. Well, now I check and if I don't get the proper image I just repeat request and this way all seem work out fine. At least, until I stumble upon something else.

Last edited by idelovski; Sep 1, 2011 at 03:32 PM.
idelovski is offline   0 Reply With Quote
Old Sep 2, 2011, 12:32 AM   #5
kikovi
Thread Starter
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by idelovski View Post
This is wrong:

Code:
   NSMutableArray *data = [result objectForKey:@"data"];
   NSMutableArray *tmpFriendID = [data valueForKey:@"id"];
   NSMutableArray *tmpFriendName = [data valueForKey:@"name"];
In the first line you'll get array of dictionaries, so you need an -objectAtIndex: at some place. Something like this:

Code:
   NSArray       *data = [result objectForKey:@"data"];
   NSDictionary  *person = [data objectAtIndex:0];  // or in a loop
      
   NSString  *name = [person objectForKey:@"name"];
   NSString  *friendId = [person objectForKey:@"id"];
And you need to check everything you get from the server. Use isKindOfClass: on almost anything you get as response and check if it's nil.

Today I had a crash with the code that handles friends icons. My code would receive all the images except one, and then I had a crash. In debugger I found the reason, I got something useless as a result so -imageWithData: returned nil and in the next line I tried to put it into a dictionary so I had a crash. Well, now I check and if I don't get the proper image I just repeat request and this way all seem work out fine. At least, until I stumble upon something else.
I don't think I need objectAtIndex since valueForKey:@"id" automatically checks all the objects and take their IDs into an array.

I ve added some isKindOfClass to reduce errors in future, but the problem remais. The issue is that the requestDidLoad doesn't even get loaded, I can't even po result in the debugger. The ID for event sent in request is correct - checked in Facebook graph api. Any more ideas what is going on?

Last edited by kikovi; Sep 2, 2011 at 03:10 AM.
kikovi is offline   0 Reply With Quote
Old Sep 2, 2011, 05:48 AM   #6
idelovski
macrumors regular
 
Join Date: Sep 2008
> I don't think I need objectAtIndex since valueForKey:@"id" automatically checks all the objects and take their IDs into an array.

Oh, oh. TIL that you can get values from array of dictionaries this way. This is so cool. I'm sure I'll need that trick one of these days.

> The issue is that the requestDidLoad doesn't even get loaded...

Put breakpoints in FBRequest.m in SDK, maybe in -connection:didReceiveResponse: and related delegate methods. Then inside -handleResponseData: and maybe -serializeURL: to see what url string do you have.

Last edited by idelovski; Sep 2, 2011 at 06:16 AM.
idelovski is offline   0 Reply With Quote
Old Sep 7, 2011, 04:38 AM   #7
kikovi
Thread Starter
macrumors newbie
 
Join Date: Aug 2011
Fixed, shouldn't release album so early.. Thanks for help everyone, though.
kikovi is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Facebook Graph API works in web browser, not in iOS SDK. Nobita iPhone/iPad Programming 0 Jan 28, 2011 06:08 AM
getting status messages from facebook using Graph API kingthong iPhone/iPad Programming 2 Jan 21, 2011 04:02 AM
iMac 27" doesn't get past apple loading screen kroeks iMac 5 Nov 9, 2010 05:12 PM
Runtime's exec() api doesn't work on Tiger vikasu Mac Programming 1 Feb 11, 2008 11:52 AM
InetAddress api doesn't work on my MAC vikasu Mac Programming 2 Jan 22, 2008 02:56 AM


All times are GMT -5. The time now is 03:00 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC