In my opinion, much more elegant way to trigger Facebook login programmatically, is by managing session for example:
-(void)loginLogout
{
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];
}
else
{
// Initialize a session object
FBSession *session = [[FBSession alloc] initWithPermissions:@[@"publish_actions", @"user_photos"]];
// Set the active session
[FBSession setActiveSession:session];
// Open the session
[session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if(error == nil)
{
NSLog(@"login successful");
// Respond to session state changes,
// ex: updating the view
}
else
{
NSLog(@"login unsuccessful");
}
}];
}
}
Moreover, changing session state will by noticed by hidden LoginView, and its delegate methods like
loginViewShowingLoggedInUser:(FBLoginView *)loginView
will be triggered (without mentioned earlier ugly pop).