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 Facebook Login for iOS - Quickstart) 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 track currentAccessToken changes with FBSDKAccessTokenDidChangeNotification in NSNotificationCenter. This allows you to respond to changes in the user's login state.

[[NSNotificationCenter defaultCenter] addObserverForName:FBSDKAccessTokenDidChangeNotification
                                                  object:nil
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:
 ^(NSNotification *notification) {
   if (notification.userInfo[FBSDKAccessTokenDidChangeUserID]) {
     // Handle user change
   }
 }];

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 determine if the user has changed.

Profiles

FBSDKProfile contains public profile information, allowing you to personalize your app with the user's name and profile picture. You can load the logged in user's profile using loadCurrentProfileWithCompletion:.

[FBSDKProfile loadCurrentProfileWithCompletion:
 ^(FBSDKProfile *profile, NSError *error) {
   if (profile) {
     NSLog(@"Hello, %@!", profile.firstName);
   }
 }];

You can set the enableUpdatesOnAccessTokenChange property to true to have the profile automatically loaded to [FBSDKProfile currentProfile]. This also lets you to observe the FBSDKProfileDidChangeNotification to respond to profile changes:

[FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
[[NSNotificationCenter defaultCenter] addObserverForName:FBSDKProfileDidChangeNotification
                                                  object:nil
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:
 ^(NSNotification *notification) {
   if ([FBSDKProfile currentProfile]) {
     // Update for new user profile
   }
 }];

Showing Profile Pictures

The FBSDKProfilePictureView class provides an easy way to display someone's Facebook profile picture. Simply set the profileID property on the instance. You can set it to a value of [[FBSDKAccessToken currentAccessToken] userID] to show the profile picture of the person currently logged in.

FBSDKProfilePictureView *profilePictureView = [[FBSDKProfilePictureView alloc] init];
profilePictureView.frame = CGRectMake(0,0,100,100);
profilePictureView.profileID = [[FBSDKAccessToken currentAccessToken] userID];
[self.view addSubview:profilePictureView];