适用于iOS的Facebook SDK v4.0 - 未设置FBSDKProfile currentProfile [英] Facebook SDK v4.0 for iOS - FBSDKProfile currentProfile not being set

查看:364
本文介绍了适用于iOS的Facebook SDK v4.0 - 未设置FBSDKProfile currentProfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的Facebook SDK升级为我的iOS应用程序4.0。

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

我的登录工作正常,但根据文档,我现在应该使用 FBSDKProfile.currentProfile() 访问个人资料信息。

I've got the log in working okay, however, according to the documentation, I'm now supposed to use FBSDKProfile.currentProfile() to access profile information.

但是,这个值似乎总是 nil ,即使我的个人资料图片正在显示(通过 FBSDKProfilePictureView )和我的 FBSDKAccessToken.currentAccessToken()不是 nil

However, this value always seems to be nil, even though my profile picture is being displayed (through a FBSDKProfilePictureView) and my FBSDKAccessToken.currentAccessToken() is not nil.

这是我的登录 ViewController:

import UIKit

class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {

    @IBOutlet weak var fbLoginButton: FBSDKLoginButton!
    @IBOutlet weak var fbProfilePicture: FBSDKProfilePictureView! //displays a picture

    override func viewDidLoad() {
        super.viewDidLoad()
        self.fbLoginButton.delegate = self
        FBSDKProfile.enableUpdatesOnAccessTokenChange(true)
        if FBSDKAccessToken.currentAccessToken() != nil {
            println("\(FBSDKAccessToken.currentAccessToken().userID)") //works
        }
        self.fbLoginButton.readPermissions = ["public_profile", "email", "user_friends"]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        println(FBSDKProfile.currentProfile()) //is nil
    }

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    }
}

有什么想法?

推荐答案

在登录回调时,可能尚未完成FBSDKProfile提取。相反,您可以观察FBSDKProfileDidChangeNotification通知帖子。

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

这篇关于适用于iOS的Facebook SDK v4.0 - 未设置FBSDKProfile currentProfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆