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

前端 未结 8 2603
星月不相逢
星月不相逢 2020-12-25 13:35

I\'ve just \"upgraded\" my Facebook SDK to 4.0 for my iOS app.

I\'ve got the log in working okay, however, according to the documentation, I\'m now supposed to use

相关标签:
8条回答
  • 2020-12-25 14:27

    It seems like you need to call the AppDelegate method to initialize the SDK before you call enableUpdatesOnAccessTokenChange:YES

    I made my AppDelegate didFinishLaunching method like this

    BOOL fbsdk = [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; [FBSDKProfile enableUpdatesOnAccessTokenChange:YES]; return fbsdk;

    That seemed to work. You still might need to do a /me request if you need items not in the profile object.

    0 讨论(0)
  • 2020-12-25 14:28

    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!) {
    
    }
    

    }

    0 讨论(0)
提交回复
热议问题