带有Firebase问题的facebookLogin.logInWithReadPermissions

时间:2016-04-15 04:20:50

标签: swift firebase facebook-login firebase-authentication

我能够使用基本的SDK程序成功验证使用facebook进行登录,但在尝试使用Firebase进行身份验证时遇到了一些困惑。我已阅读文档并复制并粘贴代码,但我仍然收到一条警告,内容为

'logInWithReadPermissions(_:handler:)' is deprecated: use logInWithReadPermissions:fromViewController:handler: instead facebookLogin.logInWithReadPermissions(["email"], handler: instead. 

1)这个警告意味着什么,我该如何解决? 2)通过电子邮件和密码登录,您会看到已创建的注册用户,但我如何知道并查看用户是否在Firebase数据库中注册了Facebook身份验证?

感谢您的帮助或指导!

import UIKit
import Firebase
import FBSDKCoreKit
import FBSDKLoginKit


class ViewController: UIViewController, FBSDKLoginButtonDelegate {

    let loginButton: FBSDKLoginButton = {
        let button = FBSDKLoginButton()
        button.readPermissions = ["email"]
        return button
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(loginButton)
        loginButton.center = view.center
        loginButton.delegate = self

        let ref = Firebase(url: "https://my-app.firebaseio.com")
        let facebookLogin = FBSDKLoginManager()

        facebookLogin.logInWithReadPermissions(["email"], handler: {
            (facebookResult, facebookError) -> Void in
            if facebookError != nil {
                print("Facebook login failed. Error \(facebookError)")
            } else if facebookResult.isCancelled {
                print("Facebook login was cancelled.")
            } else {
                let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
                ref.authWithOAuthProvider("facebook", token: accessToken,
                    withCompletionBlock: { error, authData in
                        if error != nil {
                            print("Login failed. \(error)")
                        } else {
                            print("Logged in! \(authData)")
                        }
                })
            }
        })

    }


    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        if error == nil {
            print("completed login")
            self.performSegueWithIdentifier("showNew", sender: self)
        }

        else {
            print(error.localizedDescription)
        }
    }


    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
        print("user logged out")
    }

    func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool {
        return true
    }

}  

1 个答案:

答案 0 :(得分:0)

尝试类似的事情(编译时没有警告我):

let currentToken = FBSDKAccessToken.currentAccessToken()

    // Show login only if we had not logged in before
    if (currentToken == nil || !currentToken.hasGranted("email")) {

        let ref = Firebase(url: "https://my-app.firebaseio.com")
        let facebookLogin = FBSDKLoginManager()
        facebookLogin.logInWithReadPermissions(["email"], fromViewController: self, handler: {
            (facebookResult, facebookError) -> Void in
            if facebookError != nil {
                log.error("Facebook login failed. Error \(facebookError)")
.
.
.