我正在使用sdk 3.1并尝试使用friendpickercontroller,但不知何故,表格在我的应用上加载为空。
这是我的代码,你能给出提示吗?
由于
- (void) loadFacebookFriendsPicker:(UINavigationController *)senderNavigationController {
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;
}
}];
}
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];
[senderNavigationController pushViewController:self.friendPickerController animated:YES];
}
答案 0 :(得分:0)
你的friendPickerController不应该在完成处理程序中吗?你现在这样做的方式,当你访问它时,friendPickerController将是nil,因为完成处理程序是异步执行的。
将您的friendPickerController登录名移至具有条件FBSessionStateOpen的switch case块。像这样:
switch (state) {
case FBSessionStateOpen: {
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];
[senderNavigationController pushViewController:self.friendPickerController animated:YES];
}
(虽然不确定在这里调用pushViewController)
答案 1 :(得分:0)
您可能需要在app Delegate
中使用此功能// FBSample logic
// In the login workflow, the Facebook native application, or Safari will transition back to
// this applicaiton via a url following the scheme fb[app id]://; the call to handleOpenURL
// below captures the token, in the case of success, on behalf of the FBSession object
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}