Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
548 views
in Technique[技术] by (71.8m points)

iphone - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...