2012-09-20 2 views
2

iOS 6.0에서 버튼 클릭시 페이스 북에 연결해야합니다. 프로젝트에 소셜 및 계정 프레임 워크를 추가했습니다. 나는 장소에 체크인 할 수 있지만 페이스 북에 올린 글에 대해 친구를 태그 할 수는 없습니다. 페이스 북 친구 목록을 가져 오는 방법은 무엇입니까?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"); 
} 

}

답변