简体   繁体   中英

Facebook Login with iOS 6 application using storyboard

i new to iOS especially to social media framework such as facebook. I try to understand the tutorial offer by facebook but they did it in xib format and i seem to be lost. i trying to build an application using storyboard. Please provide me with some links to for creating iOS 6 facebook login application using storyboard. Thankyou

First you need to import the Social and Account Framework into your App. Add button onStoryBoard. and write SlComposerCode into that button.

 -(Void)BtnClicked:(id)sender
    {
    ACAccountType *facebookTypeAccount = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];


        [accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                               options:@{ACFacebookAppIdKey: @"131740927031850", ACFacebookPermissionsKey: @[@"email"]}
                                            completion:^(BOOL granted, NSError *error) {
                                                if(granted){
                                                    NSArray *accounts = [accountStore accountsWithAccountType:facebookTypeAccount];
                                                    _facebookAccount = [accounts lastObject];
                                                    ACAccountCredential *fbCredential = [_facebookAccount credential];
                                                    accessToken = [fbCredential oauthToken];
                                                    NSLog(@"Facebook Access Token: %@", accessToken);
                                                    NSLog(@"Success");

                                                    [self facebook];
                                                }else{
                                                    NSLog(@"Fail");
                                                    NSLog(@"Error: %@", error);
                                                }
                                            }];

        if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
        {
            SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
            [tweetSheet setInitialText:@"posting from my own app! :)"];
            [tweetSheet addURL:[NSURL URLWithString:@"www.google.com"]];
            [tweetSheet addImage:[UIImage imageNamed:@"57.png"]];




            [self presentViewController:tweetSheet animated:YES completion:nil];


        }
        else
        {
            UIAlertView *alertView = [[UIAlertView alloc]
                                      initWithTitle:@"Sorry"
                                      message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
                                      delegate:self
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];
            [alertView show];
        }

    }

    - (void)facebook
    {

        NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];
        NSLog(@"URl:-%@",meurl);
        SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                  requestMethod:SLRequestMethodGET
                                                            URL:meurl
                                                     parameters:nil];

        merequest.account = _facebookAccount;

        [merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
            NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

            NSLog(@"Parsed Data:-%@", meDataString);

        }];

    }

Try this code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM