Facebook iOS SDK v4.0 Check User Session State

danielmhanover picture danielmhanover · Mar 25, 2015 · Viewed 8k times · Source

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.

Answer

Douglas Ferreira picture Douglas Ferreira · Mar 26, 2015

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.