尝试使用Facebook(IOS)登录时应用崩溃

时间:2016-09-30 14:47:59

标签: facebook-login swift3 firebase-authentication

描述/问题

我使用Firebase作为我的数据库,并使用Facebook登录作为我的登录方法。我已按照FirebaseFacebook上的文档进行操作,但遇到了问题。当我尝试登录时,收到以下错误消息:

“第1行:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)”行let credential = FIRFacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)

我做错了什么?我点击Facebook登录按钮后立即发生错误。

代码

import UIKit
import FBSDKLoginKit
import FirebaseAuth

class ViewController: UIViewController, FBSDKLoginButtonDelegate {

    var loginButton = FBSDKLoginButton()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Optional: Place the button in the center of your view.
        self.loginButton.center = self.view.center
        self.loginButton.readPermissions = ["public_profile", "email", "user_friends"]
        self.loginButton.delegate = self

        self.view.addSubview(loginButton)

        //Create label with text and position
        let label = UILabel(frame: CGRect(x: self.view.bounds.width / 2 - 100, y: self.view.bounds.height / 2 - 100, width: 200, height: 100))
        label.text = "Drag me!"
        label.textAlignment = NSTextAlignment.center
        self.view.addSubview(label)

        //Gesture recognition
        let gesture = UIPanGestureRecognizer(target: self, action: #selector(wasDragged(gesture:)))
        label.addGestureRecognizer(gesture)
        label.isUserInteractionEnabled = true

    }

        // Gesture transition
    func wasDragged(gesture: UIPanGestureRecognizer) {

        let translation = gesture.translation(in: view) //self.view
        let label = gesture.view!

        label.center = CGPoint(x: self.view.bounds.width / 2 + translation.x, y: self.view.bounds.height / 2 + translation.y)

        let xFromCenter = label.center.x - self.view.bounds.width / 2
        let scale = min(100 / abs(xFromCenter), 1)
        var rotation = CGAffineTransform(rotationAngle: xFromCenter / 200)
        var stretchAndRotation = rotation.scaledBy(x: scale, y: scale)

        label.transform = stretchAndRotation


        if gesture.state == UIGestureRecognizerState.ended {

            if label.center.x < 100 {

                print("Not chosen")

            } else if label.center.x > self.view.bounds.width - 100 {

                print("Chosen")

            }

            rotation = CGAffineTransform(rotationAngle: 0)
            stretchAndRotation = rotation.scaledBy(x: 1, y: 1)
            label.transform = stretchAndRotation
            label.center = CGPoint(x: self.view.bounds.width / 2, y: self.view.bounds.height / 2)

        }

    }

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

    // 
    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
        print("User Logged In")

        let credential = FIRFacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)

        FIRAuth.auth()?.signIn(with: credential) { (user, error) in
            print("User Logged Into Firebase App")
        }

    }

    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
        print("User Did Logout")
    }

}

0 个答案:

没有答案