Search code examples
iphoneobjective-cfacebookios6

how to do facebook login in iOS 6?


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 ?


Solution

  • 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. :-)