Facebook login - if a user account is present (and the application is not installed), the login is not performed

I just found this problem while testing my application and it really starts to annoy me. So what the environment looks like:

  • Facebook application not installed.
  • The user is registered in the iOS system account (in the settings → Facebook)

When my application tries to authenticate a user for the first time, it provides this wall of text: (I tried to clear it a bit)

2014-01-30 15:20:31.439 Unifeed[2140:70b] Session is <FBSession: 0xb74f9e0, state:         
FBSessionStateClosedLoginFailed, 
loginHandler: 0x0, appID: *************, urlSchemeSuffix: ,    
 tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xb73bd90>,
 expirationDate: (null),     
refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>

2014-01-30 15:20:31.440 Unifeed[2140:70b] Session closed
2014-01-30 15:20:31.440 Unifeed[2140:70b] User logged out

2014-01-30 15:20:31.441 Unifeed[2140:70b] Error occured Error Domain=com.facebook.sdk Code=2    
"The operation couldn’t be completed. (com.facebook.sdk error 2.)"
UserInfo=********  
{com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginCancelled,    
com.facebook.sdk:ErrorInnerErrorKey=Error Domain=com.apple.accounts Code=7 "The operation 
couldn’t be completed. (com.apple.accounts error 7.)", 
com.facebook.sdk:ErrorSessionKey=<FBSession: 0xb74f9e0, state: FBSessionStateClosedLoginFailed,   
loginHandler: 0x0, appID: ************, urlSchemeSuffix: 
, tokenCachingStrategy:<FBSessionTokenCachingStrategy: 
0xb73bd90>, expirationDate: (null), refreshDate: (null), 
attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}

2014-01-30 15:20:31.441 Unifeed[2140:70b] User cancelled login
2014-01-30 15:20:31.445 Unifeed[2140:70b] User logged out

, , , , , . , , , ... Facebook , ... , , App, FB, .... - ?

: ( FB)

- (void) facebookSessionChange {
// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
    || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {

    // Close the session and remove the access token from the cache
    // The session state handler (in the app delegate) will be called automatically
    [FBSession.activeSession closeAndClearTokenInformation];

    // If the session state is not any of the two "open" states when the button is clicked
} else {
    // Open a session showing the user the login UI
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];
}
 }

 - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
 {

NSLog(@"Session is %@", session);
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
    NSLog(@"Session opened");
    // Show the user the logged-in UI
    [self userLoggedIn];
    return;
}
if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
    // If the session is closed
    NSLog(@"Session closed");
    // Show the user the logged-out UI
    [self userLoggedOut];
}

// Handle errors
if (error){
    NSLog(@"Error occured %@", error);
    if ([FBErrorUtility shouldNotifyUserForError:error] == YES){
        NSLog(@"Error occured %@", error);
    } else {

        // If the user cancelled login, do nothing
        if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
            NSLog(@"User cancelled login");

            // Handle session closures that happen outside of the app
        } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession){
            NSLog(@"Session is no longer valid");

        } else {
            //Get more error information from the error
            NSDictionary *errorInformation = [[[error.userInfo objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"];
            NSLog(@"Error occured : %@", [errorInformation objectForKey:@"message"]);
        }
    }
    // Clear this token
    [FBSession.activeSession closeAndClearTokenInformation];
    // Show the user the logged-out UI
    [self userLoggedOut];
}
}

// Show the user the logged-out UI
- (void)userLoggedOut 
{
    NSLog(@"User logged out");
}

// Show the user the logged-in UI
- (void)userLoggedIn 
{
    NSLog(@"User Logged in");
    [_delegate doneLogginginToFb];
}

, ... ?

+4
3

, , Facebook ( - , , " "...) , Facebook, , , , FBErrorCategoryUserCancelled.

, > > Reset, reset . , .

+4

Facebook > > >

+

.

+4

I had the same problem and it drove me crazy. I was fixed by updating the Facebook SDK to the latest version.

Not sure if this was a problem for you, but I hope this helps someone.

+2
source

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


All Articles