-1

I have a single view application that utilizes Parse to create a PFLogInViewController. Before the BeaconViewController can be accessed, the user must authenticate with Facebook - this is working fine. My issue is with the logout portion - after the user's session is destroyed, I need the PFLogInViewController to reappear. I tried to accomplish this by popping to the RootViewController, but this is not resolving the issue.

I referenced this thread as well as this one, but again did not have any luck.

Here is BeaconViewController.m with the authentication and logout logic

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    FBRequest *request = [FBRequest requestForMe];
    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error) {
            [self dismissViewControllerAnimated:YES completion:nil];
            [self pictureRequest];
        }
        else if (error) {
            NSLog(@"facebook session was invalid");
            [self logoutButtonAction:nil];
            PFLogInViewController *login = [[PFLogInViewController alloc] init];
            login.fields = PFLogInFieldsFacebook;
            login.delegate = self;
            NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
            login.facebookPermissions = permissionsArray;
            [self presentViewController:login animated:YES completion:nil];
        }
        else {
            NSLog(@"Some other error: %@", error);
        }
    }];
}


- (IBAction)logoutButtonAction:(id)sender {
    [PFUser logOut];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

enter image description here

Community
  • 1
  • 1
Anconia
  • 3,888
  • 6
  • 36
  • 65
  • FYI. `viewDidLoad` and `viewDidAppear` are not for you to call. They are for the system to call. – Daniel T. Nov 04 '14 at 21:52
  • Also, please explain the downvote - I researched this to the best of my ability beforehand and provided necessary background details – Anconia Nov 04 '14 at 22:19
  • 2
    You should try to phrase your question in a more generic way and decouple it from irrelevant specifics (PFViewController, Facebook, blah) of your project. At the same time, you're leaving out essential information (what controller is presenting this controller). While I have an idea what's the cause of your issue (you cannot dismiss and reshow a view controller from the view controller that is about to be shown), the solution to this is to read up the basics of View Controllers and not hack around your missing basic knowledge about using view controller properly: http://bit.ly/1pifOy5 – auco Nov 04 '14 at 22:32
  • @auco How blessed am I to have your words of wisdom - and that paired with your link to intro to ViewControllers makes me the luckiest fellow to walk on this big blue blob we all call home. Thanks for sparing your breath on dim-witted students like myself. – Anconia Nov 04 '14 at 22:54
  • @Anconia: I'll take it as a compliment :-) I sure remember that starting to code for iOS is not easy, because you really want to learn about the many (very smart - but for beginners often confusing) software design patterns and general concepts ("Don't fight the frameworks"). Esp ViewControllers are a very essential concept on iOS. But once you get the big picture, you will be able to use them right and start to embrace the beauty of Apple's engineering ;-) – auco Nov 05 '14 at 22:56

3 Answers3

0

Try using:

  [self.navigationController popViewControllerAnimated:YES];
Choppin Broccoli
  • 3,048
  • 2
  • 21
  • 28
0

Change your segue type to push. Add this line of code in your IBAction action method.

- (IBAction)logoutButtonAction:(id)sender
{
   [self.navigationController popViewControllerAnimated:YES];
}
Priyatham51
  • 1,864
  • 1
  • 16
  • 24
0

I resolved this by abstracting the logic for presenting the PFLogInViewController into a helper method and calling that upon logout.

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    FBRequest *request = [FBRequest requestForMe];
    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error) {
            [self dismissViewControllerAnimated:YES completion:nil];
            [self pictureRequest];
        }
        else if (error) {
            NSLog(@"facebook session was invalid");
            [self logoutButtonAction:nil];
            [self presentPFLogInViewController];
        }
        else {
            NSLog(@"Some other error: %@", error);
        }
    }];
}

-(void)presentPFLogInViewController {
    PFLogInViewController *login = [[PFLogInViewController alloc] init];
    login.fields = PFLogInFieldsFacebook;
    login.delegate = self;
    NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
    login.facebookPermissions = permissionsArray;
    [self presentViewController:login animated:YES completion:nil];
}

- (IBAction)logoutButtonAction:(id)sender {
    [PFUser logOut];
    [self presentPFLogInViewController];
}
Anconia
  • 3,888
  • 6
  • 36
  • 65