Facebook SDK v4.0 for iOS - FBSDKProfile currentProfile not being set Facebook SDK v4.0 for iOS - FBSDKProfile currentProfile not being set ios ios

Facebook SDK v4.0 for iOS - FBSDKProfile currentProfile not being set


Don't forget FBSDKProfile.enableUpdatesOnAccessTokenChange(true)!! I struggled with this for awhile until I found that in the docs. Then subscribing to notifications on FBSDKProfileDidChangeNotification should work for the FBSDKLoginButton.

Full Example... I hook up loginButton via Interface Builder

class LoginController: UIViewController, FBSDKLoginButtonDelegate {@IBOutlet var loginButton: FBSDKLoginButton!override func viewDidLoad() {    super.viewDidLoad()    loginButton.delegate = self;    FBSDKProfile.enableUpdatesOnAccessTokenChange(true)    NSNotificationCenter.defaultCenter().addObserver(self, selector: "onProfileUpdated:", name:FBSDKProfileDidChangeNotification, object: nil)}func onProfileUpdated(notification: NSNotification){}func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!){}func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {}

}


For those of you who are looking for a more updated answer and a cleaner approach than using the NSNotificationCenter, there is a class method on FBSDKProfile that you can call after logging in that looks like:

[FBSDKProfile loadCurrentProfileWithCompletion:^(FBSDKProfile *profile, NSError *error) {}];


The FBSDKProfile fetch may not have been completed by the time of the login callback. Instead you can observe for a 'FBSDKProfileDidChangeNotification' notification post.