我正在创建一个想要列出 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:]
}