New facebook-ios-sdk: Howto build an “old style” within-the-app login dialog

January 10, 2011

With the new facebook-ios-sdk we have got a “single sign on” feature. The good thing is, that this really sounds nice and handy. The bad thing is, that sometimes this SSO simply does not work. Some users have trouble to find the “OK” button to continue the login process. Also your application has to have multitasking abilities.

Well, I really do not like it if my app users can not use my app because facebook login masks are not working. So, I prefer to enable my users to disable the SSO (within the app settings) and popup the facebook login dialog myself.

Here is the code you need:

Facebook *fb = [[Facebook alloc] initWithAppId:FB_APP_ID];
self.facebook = fb;
[fb release];
// Setting the sessionDelegate is important for current SDK version,
// otherwise fbDidLogin or fbDidNotLogin is not called.
self.facebook.sessionDelegate = self;

// Define some dialog params
NSMutableDictionary *params =
  [NSMutableDictionary dictionaryWithCapacity:10];

[params setObject:FB_APP_ID forKey:@"client_id"];
[params setObject:@"publish_stream" forKey:@"scope"]

// Now popup the login dialog
[self.facebook dialog:@"oauth" andParams:params andDelegate:self]


Details for dialog parameters you can find on facebook dialog documentation page:

If you find this code snipped useful, please share it.

4 Responses to “New facebook-ios-sdk: Howto build an “old style” within-the-app login dialog”

  1. Hi mike,

    super Arbeit. Ich habe mich tot gesucht bevor ich das hier gefunden habe.

    Aber wie prüfst du ob die Session valid ist oder nicht? Denn mit deinem Ansatz funktioniert die Methode isValidSession nicht mehr.


    Schöne Grüße

  2. Thanks so much for the post! The FB documentation is really sparse and lame and I couldn’t figure out how to pop the dialog. Thanks!

  3. A session can always be invalidated (even if it not yet expired by expiration time) … to check the validity of a access token you need to make a call to facebook (eg. to /me) … please always check return results for any fb call for an “expired” ooauth access token

  4. FYI to those looking to to do this. If you leave the default behavior of it opening safari separately, it reduces the likelihood of the user having to enter the username and password again. Opening it inline they’ll definitely have to type it. If they’re already signed in in safari (or their facebook app) and use the SSO behavior, they’ll only have to click okay or allow.

Leave a Reply