zeevblu
zeevblu

Reputation: 1059

Facebook SessionState always not FBSessionStateCreatedTokenLoaded

I use the latest Facebook SDK (3.1.1).

I wrote a function in my AppDelegate that checks the current session and creates or opens a session according to the state.

The second conditions always return NO and go to show login screen.

I don't understand way.

AppDelegate method:

if (facebook.isOpen == NO)
{
   facebook = [[FBSession alloc] initWithPermissions:permission];

    if (facebook.state == FBSessionStateCreatedTokenLoaded)
    {
        [facebook openWithCompletionHandler:^(FBSession *session,FBSessionState status,NSError *error)
        {
            // load user details
        }];
    }
    else
    {
        // show login screen
    }
}

Upvotes: 3

Views: 1236

Answers (2)

Mohamed Elkassas
Mohamed Elkassas

Reputation: 869

if the session state equal to FBSessionStateCreatedTokenLoaded it means that there is a cached accessToken, a call to open* will result in an open session, without UX or app-switching

-(BOOL)validFBSessionExists{
        if (FBSession.activeSession.isOpen){
            NSLog(@"Facebook accessToken:%@",FBSession.activeSession.accessTokenData.accessToken);
            return YES;
        }
        else if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded)
        {
            // Cached token exist, Session needs to be re-opened
            [FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:nil];
            return YES;
        }
        return NO;
}

Upvotes: 0

Abhishek
Abhishek

Reputation: 149

There is a property access token in the FbSession class.

Use that string in order to check the login status.

If you are getting null in that string it means your session is expired but if you are getting some value in that is means you are still login in the app and you can do what ever you want.

Regards

Abhishek Goyal

Upvotes: 1

Related Questions