0

我正在使用 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];

}
4

2 回答 2

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)

于 2012-12-23T15:41:18.197 回答
0

您可能需要在您的应用程序委托中具有此功能

// 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];
}
于 2013-07-19T02:19:53.743 回答