3

My app uses the facebook login to authenticate the users, I heard about the facebook integration become inside the iOS SDK itself,

now if the integration become inside the iOS itself can i use it to login without importing the facebook SDK and how if yes? also my app will run the iOS 6 as a release target ?

Omar Freewan
  • 2,678
  • 4
  • 25
  • 49

2 Answers2

12

Well, First of all you have to add the Social.framework in to your project.

Step 2 : You need to import two classes.Import the needed classes.

#import <Social/Social.h>
#import <Accounts/Accounts.h>

Step 3 : I am going forward in the assumption that you have a button for Facebook in your app. At the button click write these lines. You are done. :-)

- (IBAction)facebookButtonClicked:(id)sender
{
    if([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook])
    {
        // Facebook Service Type is Available

        SLComposeViewController *slVC   =   [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeFacebook];
        SLComposeViewControllerCompletionHandler handler    =   ^(SLComposeViewControllerResult result)
        {
            if (result == SLComposeViewControllerResultCancelled)
            {
                NSLog(@"Cancelled");

            }
            else
            {
                NSLog(@"Done");
            }

            [slVC dismissViewControllerAnimated:YES completion:Nil];
        };
        slVC.completionHandler          =   handler;
        [slVC setInitialText:@"Test Post from iOS6"];
        [slVC addURL:[NSURL URLWithString:@"http://www.apple.com"]];
        [slVC addImage:[UIImage imageNamed:@"someimage.png"]];

        [self presentViewController:slVC animated:YES completion:Nil];
    }
    else
    {
        NSLog(@"Service Unavailable!!!");
    }
}

The above given is the basic steps. For more you can refer This.

Edit : For Facebook user information refer this answer.

Happy Coding. :-)

Community
  • 1
  • 1
Mathew Varghese
  • 4,527
  • 2
  • 17
  • 26
2

You need to import the Facebook SDK 3.x anyway.The only difference in login poroces is that if the user is already logged in with the native facebook integration, your app will not sent to background while user tries to login.In other words login does not open the web page of facebook or optionally installed facebook app.Ios shows a uilaertview that says you app wants to access Facebook ant thats all.If user clicks ok you app will be allwed and you can see it on the settings app unde facebook.

From the implementation perspective it does not make any difference.You can use the tutorial on facebook developer homepage.

http://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/

Ilker Baltaci
  • 11,644
  • 6
  • 63
  • 79