Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:21:38+00:00 2026-06-11T14:21:38+00:00

I have a small app that attempts to do basic login with FB using

  • 0

I have a small app that attempts to do basic login with FB using the exact methodology used in the Facebook tutorial for logging in here: https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/

The desired behavior is that the user be able to login to FB and stay logged in until they have explicitly chosen to log out by clicking on the logout button. They should stay logged in across launches of the app, even if the app is forcibly killed (but not deleted).

What is happening is that after clicking on the Login button, the app correctly logs the user in, but once I navigate back to the root view controller, and then back to the FacebookViewController, the button shows Login again, instead of log out. Something somewhere is killing the session.

I am not sure what code will be asked for, but here is a bunch:

#import "FacebookViewController.h"

@interface FacebookViewController ()

@end

@implementation FacebookViewController
@synthesize authButton;
@synthesize postSwitch;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(sessionStateChanged:)
     name:FBSessionStateChangedNotification
     object:nil];

    // Check the session for a cached token to show the proper authenticated
    // UI. However, since this is not user intitiated, do not show the login UX.
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    [appDelegate openSessionWithAllowLoginUI:NO];

    // Set toggle
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"postToFB"] isEqualToString:@"Yes"]) {
        //set to yes
        [postSwitch setOn:YES animated:YES];
    } else {
        // set to no
        [postSwitch setOn:NO animated:YES];
    }

    NSLog(@"postToFB is now %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"postToFB"]);
}

- (IBAction)authButtonAction:(id)sender
{
    AppDelegate *appDelegate =
    [[UIApplication sharedApplication] delegate];

    // If the user is authenticated, log out when the button is clicked.
    // If the user is not authenticated, log in when the button is clicked.
    if (FBSession.activeSession.isOpen) {
        [appDelegate closeSession];
    } else {
        // The user has initiated a login, so call the openSession method
        // and show the login UX if necessary.
        [appDelegate openSessionWithAllowLoginUI:YES];
    }
}

- (IBAction)togglePostSwitch:(id)sender
{
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"postToFB"] isEqualToString:@"Yes"]) {
        //set to No
        [[NSUserDefaults standardUserDefaults] setObject:@"No" forKey:@"postToFB"];
    } else {
        // set to yes
        [[NSUserDefaults standardUserDefaults] setObject:@"Yes" forKey:@"postToFB"];
    }

    NSLog(@"postToFB is now %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"postToFB"]);
}

- (void)sessionStateChanged:(NSNotification*)notification
{
    if (FBSession.activeSession.isOpen) {
        [self.authButton setTitle:@"Logout of Facebook" forState:UIControlStateNormal];

    } else {
        [self.authButton setTitle:@"Login to Facebook" forState:UIControlStateNormal];

    }
}

@end

The MainViewController (the root VC) has the following in the ViewDidLoad, and the ViewWillAppear:

- (void)viewDidLoad
{
    [[self navigationController] setNavigationBarHidden:YES animated:NO];
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    BOOL open = [appDelegate openSessionWithAllowLoginUI:NO];
    if (open) {
        NSLog(@"User session found (MainVC viewDidLoad)");
    } else {
        NSLog(@"no session detected");
    }


}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:NO];
    [[self navigationController] setNavigationBarHidden:YES animated:NO];
}

I am not real clear on why this behavior is occurring. Any help would be greatly accepted 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:21:39+00:00Added an answer on June 11, 2026 at 2:21 pm

    I actually traced this back to an error in labeling the login button. The session was always open even when the button said ‘log in’. I managed to correct this issue, but now I am discovering that indeed the app will not stay logged in across launches, but at least the login/logout button is always correct!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively small app that Im building using vb.net 2.0, and nant.
I used to have a small chat app(which was almost working), that uses PHP,
Using PHP.. I have a small app that I built that currently uses a
I have a small cakePHP app that allows for user's to login and be
I have a small web app that uses a simple username/password login scheme. I've
I have a small rails app that is using acts_as_list to implement drag and
I have small web app that generate PDF files as a report. I'm trying
I have a small app that downloads some files from a remote (HTTP) server
I have a small WinForms app that utilizes a BackgroundWorker object to perform a
I have a small helper app that I use to inject scripts into html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.