Facebook登录Firebase和LoginButton for IOS

时间:2016-04-02 02:19:45

标签: ios swift facebook facebook-authentication firebase-authentication

我正在尝试使用FacebookLoginFirebase执行Facebook Login button,但我会继续这样做

  

错误:Facebook登录被取消。

     

2016-04-01 19:08:15.721   biblos [778:408049]警告:尝试出席    上    谁的观点不在   窗口层次结构!

用户已退出...

Facebook登录被取消。

  

2016-04-01 19:08:53.675 biblos [778:408049]警告:尝试出席    上    谁的观点不在   窗口层次结构!

我的ViewController代码如下:

import UIKit
import Firebase
import FBSDKCoreKit
import FBSDKLoginKit

class ViewController: UIViewController, FBSDKLoginButtonDelegate {

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


    var loginButton = FBSDKLoginButton()
    loginButton.readPermissions = ["public_profile", "email", "user_friends"]
    loginButton.center = self.view.center
    loginButton.delegate = self
    self.view.addSubview(loginButton)

}

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




// MARK: - Facebook Login

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
{
    let ref = Firebase(url: "https://biblos-thebookapp.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 loginButtonDidLogOut(loginButton: FBSDKLoginButton!)
{
    print("User logged out...")
 }


}

1 个答案:

答案 0 :(得分:0)

不推荐使用此方法。尝试使用logInWithReadPermissions:fromViewController:handler:代替并传递你的UIViewController或nil(将使用最顶层)。

enter image description here