I’m looking to use the Facebook Api to check in users in an iOS app.
I was wondering if I have the permissions set in the AppDelegate but want the user to checkin from a different view controller do I have to declare the Facebook instance in every view controller along with the FBRequestDelegate, FBSessionDelegate, FBDialogDelegate delegate methods? or is it a one time thing in the AppDelegate?
thanks for any help.
I just dealt with the exact same problem. Here is my solution:
I Created a FBRequestWrapper which basically contains the following methods:
So all the Facebook stuff is managed in this Singleton class.
In my AppDelegate I invoke the authentication. Because in my opinion the authentication has to be done before loading all the controllers.
You can see that I also store the accessToken in the NSUserDefaults space. Because we are using the accessToken as authentication to our webservice.
My AppDelegate method is delegating the FBSessionDelegate method:
And here is the implementation of the most important method, fbDidLogin:
Here I store the accesstoken in the NSUserDefaults and load all the Controllers if everything was fine.
Now if you want to access the Facebook Graph Api from any controller outside the AppDelegate you can also use the FBRequestWrapper like that:
Here the code from the FBRequestWrapper.m: