2012-09-20 160 views
2

我不得不去連接到iOS中6.0按鈕單擊Facebook。我已經將框架社交和帳戶添加到我的項目中。我可以登錄到某個地方,但無法標記我發佈到Facebook的朋友。如何獲取Facebook好友列表?的iOS 6.0的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"); 
} 

}

回答