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 8531609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:31:33+00:00 2026-06-11T09:31:33+00:00

I am trying to integrate the new Facebook SDK for iOS and had a

  • 0

I am trying to integrate the new Facebook SDK for iOS and had a problem understanding some concepts.

  1. I authenticate using [FBSession sessionOpenWithPermissions:...] auth dialog comes up and I return the app. Auth successful.

  2. Then shut down the app, relaunch again. [[FBSession activeSession] accessToken] successfully returns previously saved token.

  3. However, at the same time, [[FBSession activeSession] isOpen] returns NO. (This means session is not ready for use.)

  4. Also, [[FBSession activeSession] state] is FBSessionStateCreatedTokenLoaded at this time. Tutorial here uses isOpen call to verify active session is loaded and opened with token.

So what do we call to open the token-loaded session without redirecting user to auth dialog?

Hints:

In FBSessionState enum, for FBSessionStateOpen it says:

Open session state indicating user has logged in or a cached token is available.

However FBSessionStateCreatedTokenLoaded is described as:

One of two initial session states indicating that a cached token was loaded; when a session is in this state, a call to open* will result in an open session, without UX or app-switching

Could you please help me figure out understanding these session transitions?

  • 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-11T09:31:34+00:00Added an answer on June 11, 2026 at 9:31 am

    I’m including a Facebook utility class I wrote that helps with understanding login state, because I expose a “logged in” / “not logged in” message to the user in my own Settings UI, in addition to using the actual ‘FBLoginView’ component when it comes time to allow the user to toggle authorization state.

    The code below is also available via this gist.

    I may not have interpreted all the FBSessionState types correctly in my switch statement, but thus far, it’s served me well in the cases I’ve tested (I’ve just put this together).

    The key thing to note, that others have alluded to, is that sometimes you have a cached authorization token that you can’t use immediately, but if you make a Facebook open call on it, you can get it to be reusable (refreshed). This open call works behind the scenes, without triggering any UI / jarring OAuth window/app switching (if you have a cached token).

    See my comments in the method isLoggedInAfterOpenAttempt. Note how I check for the state to be FBSessionStateCreatedTokenLoaded and only then, make the call to

    -openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error).

    Other tidbits about this class:

    • I have a property here to cache the logged in user, of type conforming to protocol FBGraphUser. It’s not used in any of the login methods demonstrated here, though.
    • The Facebook SDK 3.0 for iOS sample code suggests constructing your own class to hold on to and manage these kinds of operations, if you have anything more than a trivial app. This class of mine below is the beginnings of that idea for my app.
    • You can replace my ‘log4Info’ and ‘log4Debug’ macros with NSLog to get this working.
    #import "UWFacebookService.h"
    
    @implementation UWFacebookService
    
    // Static
    static const int ddLogLevel = LOG_LEVEL_DEBUG;
    
    // Strong
    @synthesize facebookGraphUser = _facebookGraphUser;
    
    
    #pragma mark - Inquiries
    
    - (BOOL)isSessionStateEffectivelyLoggedIn:(FBSessionState)state {
        BOOL effectivelyLoggedIn;
    
        switch (state) {
            case FBSessionStateOpen:
                log4Info(@"Facebook session state: FBSessionStateOpen");
                effectivelyLoggedIn = YES;
                break;
            case FBSessionStateCreatedTokenLoaded:
                log4Info(@"Facebook session state: FBSessionStateCreatedTokenLoaded");
                effectivelyLoggedIn = YES;
                break;
            case FBSessionStateOpenTokenExtended:
                log4Info(@"Facebook session state: FBSessionStateOpenTokenExtended");
                effectivelyLoggedIn = YES;
                break;
            default:
                log4Info(@"Facebook session state: not of one of the open or openable types.");
                effectivelyLoggedIn = NO;
                break;
        }
    
        return effectivelyLoggedIn;
    }
    
    /**
    * Determines if the Facebook session has an authorized state. It might still need to be opened if it is a cached
    * token, but the purpose of this call is to determine if the user is authorized at least that they will not be
    * explicitly asked anything.
    */
    - (BOOL)isLoggedIn {
        FBSession *activeSession = [FBSession activeSession];
        FBSessionState state = activeSession.state;
        BOOL isLoggedIn = activeSession && [self isSessionStateEffectivelyLoggedIn:state];
    
        log4Info(@"Facebook active session state: %d; logged in conclusion: %@", state, (isLoggedIn ? @"YES" : @"NO"));
    
        return isLoggedIn;
    }
    
    
    /**
    * Attempts to silently open the Facebook session if we have a valid token loaded (that perhaps needs a behind the scenes refresh).
    * After that attempt, we defer to the basic concept of the session being in one of the valid authorized states.
    */
    - (BOOL)isLoggedInAfterOpenAttempt {
        log4Debug(@"FBSession.activeSession: %@", FBSession.activeSession);
    
        // If we don't have a cached token, a call to open here would cause UX for login to
        // occur; we don't want that to happen unless the user clicks the login button over in Settings, and so
        // we check here to make sure we have a token before calling open
        if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
            log4Info(@"We have a cached token, so we're going to re-establish the login for the user.");
            // Even though we had a cached token, we need to login to make the session usable:
            [FBSession.activeSession openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                log4Info(@"Finished opening login session, with state: %d", status);
            }];
        }
        else {
            log4Info(@"Active session wasn't in state 'FBSessionStateCreatedTokenLoaded'. It has state: %d", FBSession.activeSession.state);
        }
    
        return [self isLoggedIn];
    }
    
    @end
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really new to ASP.NET MVC, and I'm trying to integrate some Javascript into
I'm trying to integrate the Facebook Android SDK in my app, but I can't
I am trying to integrate facebook with in my asp.net mvc web application using
I'm very new to yii, and I'm trying to integrate the facebook-wall-like style into
I am new to Scala, trying to integrate some existing Java code with Scala-specific
I am trying to integrate some new code I wrote for programmatically interacting with
I am trying to integrate a Facebook news feed into a website using Facebook
I am trying to integrate the new Open Graph objects , actions and aggregations
Hi I'm trying to integrate MySpace with my Android app. As I'm new to
I'm trying to integrate passport into my nodejs server using connect, but can't seem

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.