Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook iOs sdk iphone : Call from multiple viewcontroller

Tags:

ios

facebook

i followed the official guide from facebook dev doc for implementing SSO from my iphone app, but all is in the same viewcontroller who hold istance of "Facebook" class. Now consider i want to login in first viewcontroller of one navigationcontroller and then call graph api from the third viewcontroller of the same navigationcontroller. I think i can share the variable from one controller to another, but i wish to know if there is some "classic" ways to accomplish this. Indeed what i wish to accomplish in something like: At the start of app i wish to login and then call graph api (or fql) wherever i need in my app.

Thx

like image 378
Alessio Lunardelli Avatar asked Jan 20 '23 05:01

Alessio Lunardelli


1 Answers

I just did this:

in the YourApp_AppDelegate.h

#import "FBConnect.h"

Facebook *facebook;

@property (nonatomic, retain) Facebook *facebook;

In the YourApp_AppDelegate.m

@synthesize facebook;

Then in your application didFinishLaunchingWithOptions: function:

facebook = [[Facebook alloc] initWithAppId:@"YOUR_FACEBOOK_API"];

From your viewController.h (any of them),

#import "YourApp_AppDelegate.h"

YourApp_AppDelegate *appDelegate;

And then, in your viewController.m viewDidLoad function:

appDelegate = (YourApp_AppDelegate *)[[UIApplication sharedApplication] delegate];

Now, anytime you want to refer to your Facebook singleton, just refer to it like:

[appDelegate.facebook authorize:nil delegate:self];
like image 183
Jeffrey Berthiaume Avatar answered Jan 31 '23 00:01

Jeffrey Berthiaume