Facebook signin ios

Follow the official document procedure

1.Download SDK and setup the environment

Create new Facebook app
1.FB app 2 of 2

1.FB app 1 of 2

2.Configure the XCode project parameters


For AppTransportSecurity parameters, you can follow the Facebook direction, or you can just “allow all” as follow


3.Modify the source code

3.1 AppDelegate
#import <FBSDKCoreKit/FBSDKCoreKit.h>

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];

3.2 ViewController you want to do Facebook Signin
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

-(void)loginAsFacebook {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:  @[@”public_profile”, @”email”, @”user_friends”] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@”Process error”);
} else if (result.isCancelled) {
} else {
NSLog(@”Logged in”);

NSLog(@”[%@][%@][%@][%@]”, [[FBSDKAccessToken currentAccessToken]appID],
[[FBSDKAccessToken currentAccessToken]userID],
[[FBSDKAccessToken currentAccessToken]refreshDate],
[[FBSDKAccessToken currentAccessToken]tokenString]

//Get some profile data
FBSDKGraphRequest *requestMe = [[FBSDKGraphRequest alloc]initWithGraphPath:@”me” parameters:@{@”fields”: @”email, first_name, last_name”}];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:requestMe completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(result) {
NSString *sUserID, *sEmail, *sFirstName, *sLastName;
if ([result objectForKey:@”email”]) {
sEmail = [result objectForKey:@”email”];
if ([result objectForKey:@”first_name”]) {
sFirstName = [result objectForKey:@”first_name”];
if ([result objectForKey:@”last_name”]) {
sLastName = [result objectForKey:@”last_name”];
if ([result objectForKey:@”id”]) {
sUserID = [result objectForKey:@”id”];

NSLog(@”Customer details:[%@][%@][%@][%@]”, sUserID, sFirstName, sLastName, sEmail);

//Facebook account was authenticated OK, do whatever you need
[connection start];


By admin

Leave a Reply

Your email address will not be published. Required fields are marked *