tags:

views:

503

answers:

3

When you use facebook connect on the iPhone do you have to use the supplied login button and login screen built into the framework? The reason I ask is because I'm also using twitter and I would like to have the same user experience when they log in to user as they have when they log in to facebook. So I can either replicate the login screen facebook connect uses for twitter or just not use the facebook connect login screen all together.

+2  A: 

Login button: no. Login screen: yes. I added FB Connect integration to my FriendFeed app for iPhone, Stir, and skipped the login button. Instead, a user can choose a "Share on Facebook" button on a UIActionSheet and the app either displays a login screen or automatically posts a link depending on whether the user is authenticated.

Here's a code snippet for you. If the session is successfully resumed, then a method on your FBSession object's delegate will be called.

if (![fbSession resume]) {
  FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:fbSession] autorelease];
  [dialog show];
}

- (void)session:(FBSession*)session didLogin:(FBUID)uid {
  NSLog(@"Hooray, I'm logged in to Facebook!");
}

Apologies for being a little vague in my example above. To be honest, I find FBConnect to be a bit of a mystery and tried my best to implement it and get away from it as quickly as possible in my app. Let me know if you need more information and I'll put together a more-concrete answer.

Per the request below:

You can get an FBSession object with FBSession's +sessionForApplication:secret:delegate class method. You call -resume on the session object. If it returns YES, it'll immediately call your delegate's -session:didLogin: method, which is where you should put your FB-dependent actions. If it does not successfully -resume, then you need to create an FBLoginDialog, as seen in the code snippet above. Make sense? Let me know if you need more info

Aaron Brethorst
How did you get the fbSession object in the above code? I know how to create a new one via bringing up the login screen, but it's unclear to me how I'm supposed to get a valid session after the user has already authenticated during a previous execution of my app. Thanks.
Greg Maletic
A: 

@aaron: is there a better implementation for the FBConnect? Did you managed to login without that?

Stefan Mayr
A: 

I also would like to know more about how did you get the fbsession object in the above code. I can get everything else to work, but it is a little buggy and often crashes