iOS 6.0 Facebook连接

时间:2012-09-20 07:58:14

标签: iphone

我必须在iOS 6.0上点击按钮点击Facebook。我已将框架社交和帐户添加到我的项目中。我可以登记到某个地方但是,无法标记朋友我发布到Facebook的内容。如何获取Facebook好友列表?

我使用的代码如下所示:

- (IBAction)connectToFacebook:(id)sender
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSDictionary *options = @{
@"ACFacebookAppIDKey": @"412590558803147",
@"ACFacebookAppVersionKey": @"1.0",
@"ACFacebookPermissionsKey": @"publish_stream",
@"ACFacebookPermissionGroupKey": @"write"
};

NSLog(@"options is %@",options);

[accountStore requestAccessToAccountsWithType:accountType options:options
                                        completion:^(BOOL granted, NSError *error) {
                                            if (granted)
                                            {
                                                NSArray *accounts = [accountStore
                                                                     accountsWithAccountType:accountType];
                                            NSString *facebookAccount = [accounts lastObject];

                                                NSLog(@"facebook account %@", facebookAccount);
                                            } else {
                                                NSLog(@"%@",error);
                                                // Fail gracefully...
                                            }
                                        }];

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultCancelled) {

            NSLog(@"Cancelled");

        } else

        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Posted!!!" message:@"your status is posted to facebook successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alert show];
        }

        [controller dismissViewControllerAnimated:YES completion:Nil];
    };
    controller.completionHandler =myBlock;

    [controller setInitialText:@"This is a ios 6.0 facebook intergration application"];
    [controller addImage:[UIImage imageNamed:@"spalshimage.jpeg"]];

    [self presentViewController:controller animated:YES completion:Nil];

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

}

1 个答案:

答案 0 :(得分:2)

整合Facebook的最佳方式是使用新的iOS 6 Facebook SDK:

https://developer.apple.com/technologies/ios6/

请在朋友列表中使用此链接:

https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/show-friends/