Initial FBSession Check Fails Consistently

I have an application in which the user can select a login for FB. My code is mainly based on FB tutorials, and for the most part, the FB application and integration works as expected. The problem that I am facing is that the application does not remember from the moment of launch that the user chose to connect the application to FB. I put the check in AppDelegate.m to check the cached FBSession:

if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) { // Yes, so just open the session (this won't display any UX). NSLog(@"The state is IS 'State created token loaded'"); [self openSessionWithAllowLoginUI:NO]; } else { // No, display the login page. NSLog(@"The state is NOT 'State created token loaded'"); [self openSessionWithAllowLoginUI:YES]; } 

Each time I launch the application, the console displays the string โ€œStatus NOTโ€ The state created by the loaded token. โ€This makes me think that I am not doing something right to do this FB registration from launch to launch.

I could use some tips here. What needs to be done to make sure that "FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded" is correct when the application starts?

+4
source share
1 answer

If you have this code on the right when you start the application, note that:

FBSession.activeSession

Cannot be installed. What you want to do to check the cached token looks something like this:

 if (![self openSessionWithAllowLoginUI:NO]) { [self openSessionWithAllowLoginUI:YES]; } 

The first call with "NO" will be returned synchronously with the value "True" if there is a cache key. It does not return if there is no cached token. At this point, you can force UX to log in.

+1
source

Source: https://habr.com/ru/post/1436230/


All Articles