我知道我在正确的道路上。 试图弄清楚如何在登录到新的 View Controller 后将用户重定向。
#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;
}
关于ios - 登录facebook后如何重定向用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31644367/