Facebook使用解析登录时出错(swift 2)

时间:2016-01-31 03:23:12

标签: parse-platform login swift2 facebook-login

我一直在关注使用Facebook登录的教程。在我尝试运行它之前,我的代码(下面)没有给出任何错误。当我在模拟器中运行代码时,它会成功编译"成功"。当我点击按钮但是我得到了"线程1:信号SIGABRT"错误。我已经检查以确保我的按钮正确链接,甚至重新启动项目但我仍然得到相同的错误。如何解决这个问题?

P.S。 Error screenshot

    import UIKit
    import Parse
    import ParseFacebookUtilsV4

    class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func signInButtonTapped(sender: AnyObject) {

        let permissions = ["public_profile", "email", "user_photos"]

        if let _ = FBSDKAccessToken.currentAccessToken() {

            print("connected already")

        } else {

            PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
            (user: PFUser?, error: NSError?) -> Void in

                if let user = user {
                    if user.isNew {
                        print("User signed up and logged in through Facebook!")
                    } else {
                        print("User logged in through Facebook!")
                    }
                } else {
                    print("Uh oh. The user cancelled the Facebook login.")
                }
            }

        }

    }


}

1 个答案:

答案 0 :(得分:0)

这是错误的:

 if let _ = FBSDKAccessToken.currentAccessToken() {

        print("connected already")

应以不同的方式使用访问令牌:

if(FBSDKAccessToken.currentAccessToken() != nil) {
    // logged in

} else {

}

这应该有效:

@IBAction func signInButtonTapped(sender: AnyObject) {

    let permissions = ["public_profile", "email", "user_photos"]

    if(FBSDKAccessToken.currentAccessToken() != nil) {
        // logged in

        print("Logged In")

    } else {
        PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
            (user: PFUser?, error: NSError?) -> Void in

                if let user = user {
                    if user.isNew {
                        print("User signed up and logged in through Facebook!")
                    } else {
                        print("User logged in through Facebook!")
                    }
                } else {
                    print("Uh oh. The user cancelled the Facebook login.")
                }
            }

        }

    }
}