Facebook使用storyboard登录iOS 6应用程序

时间:2013-09-24 06:44:19

标签: ios facebook ipad

我是iOS新手,尤其是Facebook等社交媒体框架。我尝试了解facebook提供的教程,但是他们用xib格式做了,我似乎迷失了。我试图使用故事板构建应用程序。请提供一些使用storyboard创建iOS 6 facebook登录应用程序的链接。三江源

1 个答案:

答案 0 :(得分:0)

首先,您需要将社交和帐户框架导入您的应用程序。添加按钮onStoryBoard。并将SlComposerCode写入该按钮。

 -(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);

        }];

    }

试试这段代码。