I have my view controller listed below that handles the Facebook Login. As it is now, the app runs and loads a view that has the Facebook login button. Once logged in, the button changes the text to "Log out". What I would like to happen is once a user is logged in, it then goes to another view controller.
我在故事板中添加了一个新的视图控制器,并在两者之间进行了“segue”,但我觉得我错过了一些东西。如果有帮助的话,我制作的新视图控制器被命名为“homeViewController”。谢谢
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.loginView.readPermissions = @[@"public_profile", @"email", @"user_friends"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
NSLog(@"%@", user.name);
}
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
{
NSLog(@"You are logged in! :) ");
}
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView
{
NSLog(@"You are logged out! :( ");
}
- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error
{
NSString *alertMessage, *alertTitle;
if ([FBErrorUtility shouldNotifyUserForError:error])
{
alertTitle = @"Facebook error";
alertMessage = [FBErrorUtility userMessageForError:error];
}
else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession)
{
alertTitle = @"Session Error";
alertMessage = @"Your current session is no longer valid. Please log in again.";
}
else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled)
{
NSLog(@"user cancelled login");
}
else
{
alertTitle = @"Something went wrong";
alertMessage = @"Please try again later.";
NSLog(@"Unexpected error:%@", error);
}
if (alertMessage)
{
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
}
@end
只要将 Segue 附加到 Facebook 登录按钮,它就应该是您所需要的。
如果你愿意的话可以打电话
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
if(currentUser ) { //this checks that the user logged in before moving to the next view
return YES;
}
else return NO;
}
在移动到 homeViewController 之前检查用户是否成功登录。
你会做类似上面代码的事情
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)