Change View Controllers After Facebook Login

<img src="https://i.stack.imgur.com/1fq5n.png" alt="enter image description here"> 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.

I have added a new view controller in storyboard and did a "segue" between the two, but I feel like I am missing something. The new view controller I made is named "homeViewController" if that helps. Thanks

#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


The segue should be all you need as long as it is attached to the Facebook login button.

If you want you could call

- (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; }

To check that the user successfully logged in before moving to the homeViewController. you would do something like the code above


Check this initially

FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { if (status == FBSessionStateOpen || status == FBSessionStateOpenTokenExtended) { //Call your view controller after login NSLog(@"Logged in!"); } }];

If not logged in, after putting credentials of FB. Under this delegate call your VC to display after logged in

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user { //Call your view controller after login NSLog(@"%@", user.name); }

Another way is check

if (![FBSession.activeSession isOpen]) { // presentLoginViewController return; } else { [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) { if (!error) { //self.label.text = user.name; //self.userProfileImage.profileID = [user objectForKey:@"id"]; NSLog(@"FB id : %@",appContext.userName); //Present your view controller after logged in } }]; }


  • Swift class that inherits an Objective-C Base Class not casting to correct type
  • Changing cursor in CursorAdapter is not properly updating list item views
  • An unhandled exception of type 'System.AccessViolationException' occurred
  • C# TPL calling tasks in a parallel manner and asynchronously creating new files
  • Azure deployment continually recycling since upgrading the June 2012 SDK 1.7
  • how to end the nested loop
  • How to remove fragment from fragment manager when activity is restored after being destroyed
  • gmaps4rails replaceMakers flicker effect
  • Optimising asyncronus HttpClient requests
  • Dispose not working as expected in DirectorySearcher
  • x-axis labels in coreplot not displayed
  • Android: how to determine cold start
  • How do I create an image and save it for later to draw as texture in XNA?
  • What is the equivalent of Android permissions in iOS development? [duplicate]
  • jersey/tomcat Description The origin server did not find a current representation for the target res
  • Bash if statement with multiple conditions
  • JBoss External Properties Files in Classpath
  • Alert pop up with LWUIT
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • How to show dropdown in excel using jrxml (jasper api)?
  • Importing jscolor library in angular 2
  • Release, debug version and Authorization Google?
  • Websockets service method fails during R startup
  • jquery mobile loadPage not working
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • How to get next/previous record number?
  • Apache 2.4 - remove | delete | uninstall
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Proper way to use connect-multiparty with express.js?
  • Trying to get generic when generic is not available
  • embed rChart in Markdown
  • How to stop GridView from loading again when I press back button?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal