5

I want to encapsulate all my Facebook interactions within a FacebookFacade class to keep things clean and tidy. I have an instance of the iOS SDK Facebook class within my FacebookFacade.

My problem is that when I make a Graph API call within the facade, such as:

    [self.facebook requestWithGraphPath:@"me" andDelegate:self]; 

The only method of FBRequestDelegate that gets called is requestLoading: and nothing else. I have tried putting similar code in other places, like in controllers and other models, and there too not all of the FBRequestDelegate methods get called, only requestLoading:.

In fact the only way I can get the other FBRequestDelegate methods to be called is to put all my Facebook logic in the AppDelegate and make my AppDelegate the FBRequestDelegate.

Why is this the case? Am I missing something here? I definitely do not want to use the AppDelegate as my FBRequestDelegate as I don't want to confuse the purpose of the AppDelegate.

Thanks.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
RMR
  • 51
  • 1
  • 2

3 Answers3

7

Had the same problem this afternoon. Finally solved it: You HAVE TO make your FBRequest from the MAIN thread. Otherwise underlying NSURLConnect (in facebook object) never starts.

ikarius
  • 513
  • 6
  • 10
  • Oh my god this just saved me. I have spent so long debugging this facebook request. Why is this not mentioned in their documentation? – Nicolas Renold Oct 25 '11 at 08:26
  • I think it's more related to NSURLConnection and Run loops. But they should advise to perform graph requests on main thread. – ikarius Nov 22 '11 at 14:25
2

You can share your appDelegate with the other controllers in your application.

I solved this problem by importing my AppDelgate (which instantiates and allocates the facebook object in it) into my interface, i.e

#import "MyAppDelegate.h"

interface MyViewController: UIViewController <FBRequestDelegate, FBDialogDelegate, FBSessionDelegate>

This way, i can create a pointer to point to the delegate object and use the facebook methods in where i need to.

-(void) someFunction{
      MyAppDelgate *sharedAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]
      [sharedAppDelegate.facebook dialog:@"feed" andDelegate:self]; 
}

Let me know if this doesn't work

ephilip
  • 1,015
  • 1
  • 10
  • 23
  • I tried this, the delegates in my view controller still don't get called! How exactly did you setup your facebook in the delegate so you could use it in a view controller? – Alan Moore May 22 '12 at 22:52
1

Make sure that the initial object is not being released while facebook is working in the background. If it is, when facebook goes to call the delegate and finds it nil or catches an error, it will not call back.

coneybeare
  • 33,113
  • 21
  • 131
  • 183