There is no more class FBSession
in new Facebook iOS SDK v4.x. How can I find out whether user is logged in or not now? Thanks in advance.
Asked
Active
Viewed 1.0k times
16
-
4What about using [FBSDKAccessToken currentAccessToken] ? – Vincent Mar 26 '15 at 15:44
-
4"FBSession.activeSession has been replaced with [FBSDKAccessToken currentAccessToken] and FBSDKLoginManager. There is no concept of session state. Instead, use the manager to login and this sets the currentAccessToken reference." from https://developers.facebook.com/docs/ios/upgrading-4.x ? – Larme Mar 26 '15 at 15:45
2 Answers
11
Vincent is right, check [FBSDKAccessToken currentAccessToken] to determine if the user is logged in.

Chris Pan
- 1,903
- 14
- 16
-
do you know how to log the user out, i need to do that programatically – Mina Kolta Mar 31 '15 at 16:31
-
The FBSDKLoginManager has a logout method, but the online docs are currently blank. I have yet to convert to 4.0 and I have the same need. Check out the headers until https://developers.facebook.com/docs/reference/ios/current/class/FBSDKLoginManager/ is finished. – Ron Barr Mar 31 '15 at 21:54
-
do you know how to fetch the user info after a successful login, i need to get the email – OXXY Jun 11 '15 at 12:14
-
1Please how can I replace this `[FBSession openActiveSessionWithAllowLoginUI:NO];` ? – Ne AS Jul 04 '17 at 15:41
5
To check if the user logged in and if so, navigate to another view:
if ([FBSDKAccessToken currentAccessToken]) {
// User is logged in
[self performSelector:@selector(accessGrantedNavigation)
withObject:nil afterDelay:0.0];
}
-(void)accessGrantedNavigation{
[self performSegueWithIdentifier: @"segueLoginFB" sender: self];
}
To log out: (although it doesn't allow to change FB user. I think it is because Safari already takes care of that session and remains the same user.)
FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
[manager logOut];
Hope it helps.

MLBDG
- 1,357
- 17
- 23
-
2Please how can I replace this `[FBSession openActiveSessionWithAllowLoginUI:NO];` ? – Ne AS Jul 04 '17 at 15:41
-
@NeAS can you help with replacing [FBSession openActiveSessionWithAllowLoginUI:NO] ? – vishnu May 29 '20 at 07:54