Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook logging into wrong app on iOS

My iOS app uses Facebook for logging in, however my dev team recently decided to consolidate all our apps into one universal Facebook app with a common APP ID. So I went into my project and tried to change my FacebookAppID and URL Types to the right APP ID, but when I run the app and click on the login button, it redirects me to log into my old app on Facebook. I have absolutely no idea why this is happening, but here is what I have in my AppDelegate file:

/*
 Callback for session changes
*/
- (void)sessionStateChanged:(FBSession *)session
                  state:(FBSessionState) state
                  error:(NSError *)error
{
switch (state) {
    case FBSessionStateOpen:
        if (!error) {
            // We have a valid session
            NSLog(@"User session found");
        }
        break;
    case FBSessionStateClosed:
    case FBSessionStateClosedLoginFailed:
        [FBSession.activeSession closeAndClearTokenInformation];
        break;
    default:
        break;
}

[[NSNotificationCenter defaultCenter]
 postNotificationName:FBSessionStateChangedNotification
 object:session];

if (error) {
    UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"Error"
                              message:error.localizedDescription
                              delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
    [alertView show];
    }
}

/*
 * Opens a Facebook session and optionally shows the login UX.
 */
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"email",
                        @"user_games_activity",
                        @"user_location",
                        @"user_likes",
                        @"user_birthday",
                        nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
                                          allowLoginUI:allowLoginUI
                                     completionHandler:^(FBSession *session,
                                                         FBSessionState state,
                                                         NSError *error) {
                                         [self sessionStateChanged:session
                                                             state:state
                                                             error:error];
                                     }];
}

/*
 * If we have a valid session at the time of openURL call, we handle
 * Facebook transitions by passing the url argument to handleOpenURL
 */
- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {
    // attempt to extract a token from the url
    return [FBSession.activeSession handleOpenURL:url];
}
/*
 *Logout
 *
 */
- (void) closeSession {
    [FBSession.activeSession closeAndClearTokenInformation];
}
like image 769
Julian Coltea Avatar asked Mar 13 '13 21:03

Julian Coltea


People also ask

Why does Facebook log in to the wrong account?

The issue may be caused by various reasons, e.g. improper cookie settings, another person may be trying to log into your Facebook account, Facebook session expired, corrupt or wrong browser caches, malware or virus infection, etc.

How do I change my default Facebook account on iOS?

Go to Settings->Facebook (You will need to scroll down some way) and then tap your account name, then tap on 'Delete Account' you can now enter details of another account. This doesn't apply if you are using the Facebook App from the App store on your device, this is only for the built-in Facebook integration in iOS.

How do I remove Facebook login from other apps?

Tap in the top right of Facebook. Scroll down and tap Settings. Go to the Security section and tap Apps and Websites. Tap Edit next to Apps, Websites and Games, then tap Turn Off.


1 Answers

You probably have two applications on your device that have the same Facebook URL scheme in the application Info.plist. You can either:

  • Remove the old app, or
  • Reinstall the old app but remove the Facebook URL scheme from the Info.plist file beforehand

You may have more than one URL scheme. If so, you should look for the one that looks like fbxxxxxxxxxxx, which is displayed on your app page on http://developers.facebook.com/

like image 54
Alex Avatar answered Sep 21 '22 09:09

Alex