8

In the new Facebook iOS SDK, the entire login process has been revamped. The old [FBSession activeSession].isOpen trick doesn't work anymore. How can I reliably determine the state of a user's session in the new SDK?

My current thoughts are simply checking if [FBSDKProfile currentProfile] is nil, but that doesn't seem like it would be 100% accurate, or the proper, most direct way to solve this problem.

danielmhanover
  • 3,094
  • 4
  • 35
  • 51
  • Hi, Please refer my question http://stackoverflow.com/questions/29908560/how-to-track-facebook-password-change-and-profile-changes. [FBSDKAccessToken currentAccessToken] is always as token even user changed the password/removed the app in facebook. can you help me? – Nandha Apr 28 '15 at 02:55

1 Answers1

20

There are some changes on v4.0. You can check all of them here: https://developers.facebook.com/docs/ios/upgrading-4.x

In order to check user's session, now you should use [FBSDKAccessToken currentAccessToken].

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.

Douglas Ferreira
  • 2,279
  • 2
  • 27
  • 42
  • 2
    So, just check if that singleton is `nil`? – danielmhanover Mar 26 '15 at 05:13
  • Exactly, there is no session state anymore. If you have an access token, you are able to use Facebook services. – Douglas Ferreira Mar 26 '15 at 05:25
  • 3
    I'm trying to do the same, but no matter how I log the user in the `FBSDKAccessToken.currentAccessToken()` is always `nil`. Is there another way to do that? Thanks! – Hannes May 18 '15 at 15:21
  • 1
    @hannes check this question [ios Facebook SDK v4.x access token null despite being logged in via FBSDKLoginButton](http://stackoverflow.com/q/29434392/1492173) – Yevhen Dubinin Jan 19 '16 at 10:17
  • I don't know if this is helpful, but I was having the same issue because I did not set the access token. In the `didCompleteWithResult` login button delegate function, you have to set the access token by calling `FBSDKAccessToken.setAccessToken(FBSDKLoginManagerLoginResult.token)`. – Jake Jul 17 '16 at 06:14