Facebookの友達をリストしたいアプリを作成しています。そのために私は次のことをしました。
- (void)viewDidLoad
{
arrayFriends=[[NSMutableArray alloc]init];
[super viewDidLoad];
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession.activeSession openWithCompletionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
switch (state) {
case FBSessionStateClosedLoginFailed:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
break;
default:
break;
}
}];
}
}
-(void)viewWillAppear:(BOOL)animated
{
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = @"Pick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self.friendPickerController.view setFrame:CGRectMake(0, 77, 320, 383)];
[self.view addSubview:self.friendPickerController.view];
// iOS 5.0+ apps should use [UIViewController presentViewController:animated:completion:]
}