我知道我在正确的道路上。
试图弄清楚登录后如何将用户重定向到新的视图控制器。

#import "FacebookLogin.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

@implementation FacebookLogin
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
loginButton.readPermissions= @[@"public_profile", @"email"];
if ([FBSDKAccessToken currentAccessToken]) {
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                             bundle: nil];

    UIViewController *controller = [mainStoryboard instantiateViewControllerWithIdentifier: @"Main"];

    [self presentViewController:controller animated:YES completion:nil];
}
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end

最佳答案

尝试这个......

- (void)viewDidLoad
{
    [self performSelector:@selector(Fb_Login) withObject:nil];
    [super viewDidLoad];

}
-(void)Fb_Login
{
    if (!FBSession.activeSession.isOpen)
    {
        // if the session is closed, then we open it here, and establish a handler for state changes

        [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
         {
             if (error)
             {
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                 [alertView show];
             }
             else if(session.isOpen)
             {
                 [self Fb_Login];
             }

         }];
        return;
    }

10-08 03:07