Login Review

If your app asks for more than public_profile, email and user_friends, Facebook must review it before you release it. Learn more about the review process and what's required to pass review.

Login Review Guide

Custom Login Button

Instead of using the Facebook-branded login button (explained in 3. Add Facebook Login Button Code) you may want to design a custom layout and behavior. In the following code example we invoke the login dialog using the login manager class (FBSDKLoginManager) and a custom button (UIButton). You can use any other custom user interface or event handling to invoke the login dialog.

// Add this to the header of your file
#import "ViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

// Add this to the body
@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
    
  // Add a custom login button to your app
  UIButton *myLoginButton=[UIButton buttonWithType:UIButtonTypeCustom];
  myLoginButton.backgroundColor=[UIColor darkGrayColor];
  myLoginButton.frame=CGRectMake(0,0,180,40);
  myLoginButton.center = self.view.center;
  [myLoginButton setTitle: @"My Login Button" forState: UIControlStateNormal];

  // Handle clicks on the button
  [myLoginButton 
    addTarget:self 
    action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside];
 
  // Add the button to the view
  [self.view addSubview:myLoginButton];
}

// Once the button is clicked, show the login dialog
-(void)loginButtonClicked
{
  FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
  [login
    logInWithReadPermissions: @[@"public_profile"]
          fromViewController:self
                     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    if (error) { 
      NSLog(@"Process error");
    } else if (result.isCancelled) {
      NSLog(@"Cancelled");
    } else {
      NSLog(@"Logged in");
    }
  }];
}
    
@end

Using the Interface Builder

To add the Login button graphically in Interface Builder:

  1. Add a View object to your layout. Size it as you like.
  2. In Identity inspector change the Class property to FBSDKLoginButton

Now your layout looks like this:

You can now update code that runs at app launch. This loads FBSDKLoginButton before the view displays

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[FBSDKLoginButton class];
...
return YES;
}

Access Tokens

Notifications

You can also track currentAccessToken changes with FBSDKAccessTokenDidChangeNotification in NSNotificationCenter. If you track someone's login state changes you can update your UI based on their state.

The iOS SDK can update currentAccessToken over time such as when the SDK refreshes a token with a longer expiration date. Therefore you should check the userInfo dictionary in the notification for FBSDKAccessTokenDidChangeUserID to be current

Profiles

FBSDKProfile captures public profile information and is a useful way for you to display the user's name in your UI. You can enable FBSDKProfile to automatically track the currentAccessToken:

[FBSDKProfile enableUpdatesOnAccessTokenChange:YES];

Now your app can observe NSNotificationCenter for FBSDKProfileDidChangeNotification to track profile changes on [FBSDKProfile currentProfile].

This is an abstraction of [FBSDKAccessToken currentAccessToken] that automatically fetches public_profile fields and lets you know when someone's login state changes.

Track Profile Pictures

The FBSDKProfilePictureView class provides an easy way to add someone's Facebook profile image to your view. Simply set the profileID property on the instance. You can set it to a value of me to automatically track the person currently logged-in.