2

I'm having difficulties getting the Facebook Log In to kick back to the right view in my app and call the appropriate facebook functions.

In the example Facebook has simply [controller facebook] that is the view they start with. I am using a tabbar application though so I don't have the necessary reference. I made a pointer to the desired view and used it... it opened correctly but would not call any of the methods associated with facebook, specifically:

(void)fbDidLogin;

(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [[*NotReferencedViewController* facebook] handleOpenURL:url];
}

Has anyone else run into this?

CRM
  • 4,569
  • 4
  • 27
  • 33
Zach Whelchel
  • 141
  • 1
  • 6

1 Answers1

2

Not sure what example you're talking about, but you should create and store your Facebook object in a central place such as your Model or UIApplicationDelegate. Then it would be accessible through singletons so you always have access to it, for example:

[[UIApplication sharedApplication] delegate].facebook

So you can then access the facebook object from whatever view controllers need it.

When you do something like

NSArray* permissions =  [[NSArray arrayWithObjects:@"email", @"read_stream", @"publish_stream", nil] retain];

[facebook authorize:permissions delegate:self];

specifying delegate:self means you will implement methods in that class that Facebook can call to inform you of certain events. One of those methods is fbDidLogin, and in there you can do whatever you need to:

-(void)authorizeFacebook {
    NSArray* permissions =  [NSArray arrayWithObjects:@"email", @"read_stream", @"publish_stream", nil];

    [facebook authorize:permissions delegate:self];
}

// if the authorization succeeds it will come back to your app and call the method below
-(void)fbDidLogin {
    // switch view, call the facebook graph, or do whatever else you like
}

You could do this in the app delegate itself, or in a view controller.

You can see the facebook delegate methods by inspecting the .h files of the facebook SDK: Facebook.h, FacebookRequest.h, etc.

Edit

And your handleOpenURL: method should look exactly as it does in fb's example (assuming you are not handling other url schemes):

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    return [facebook handleOpenURL:url]; 
}

http://developers.facebook.com/docs/guides/mobile/#ios

pablasso
  • 2,479
  • 2
  • 26
  • 32
kball
  • 4,923
  • 3
  • 29
  • 31
  • I've put this into the appdelegate but it wont even come back to my app now after signing in. The handleOpenURL method calls for the object *facebook* to handle it but it wont even kick back now... – Zach Whelchel May 18 '11 at 06:55
  • Have you updated your plist file as shown at that link above. – kball May 18 '11 at 16:45