IOS SWIFT:您已经授权facebook ios

时间:2016-06-14 16:35:30

标签: ios swift facebook facebook-login

你好,我正在为我的IOS SWIFT APP使用Facebook登录SDK。我想知道如何检测此事件(如果用户已经被授权)并将其重定向到HomeScreen而不停留在那里。目前正在发生的事情是,当屏幕下方显示时,我按下完成按钮或确定按钮,仍显示登录屏幕。

enter image description here

 @IBAction func loginFacebookButton(sender: UIButton) {



        let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()

        fbLoginManager .logInWithReadPermissions(["email"], fromViewController: self) { (result, error) -> Void in

            if (error == nil){
                let fbloginresult : FBSDKLoginManagerLoginResult = result
                  if fbloginresult.grantedPermissions != nil {
                    dispatch_async(dispatch_get_main_queue()) {
                        self.view.addSubview(self.progressHUD)
                    }
                if(fbloginresult.grantedPermissions.contains("email"))
                {



                    self.getFBUserData()
                    //fbLoginManager.logOut()
                }else{

                print("sorry")

                }
                }}
        }
    }


    func getFBUserData(){
        if((FBSDKAccessToken.currentAccessToken()) != nil){
           // print("token not nill")
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
                if (error == nil){
                    var facebook = Facebook()
                    facebook.authenticationToken = FBSDKAccessToken.currentAccessToken().tokenString
                    facebook.email = result["email"] as? String
                    facebook.firstName = result["first_name"] as? String
                    facebook.lastName = result["last_name"] as? String
                    facebook.facebookID = result["id"] as? String

                    self.sendFBDataToServer(facebook)

                }
            })
        }
    }

1 个答案:

答案 0 :(得分:0)

perfomSegueWithIdentifier(_:)块中的if (error == nil)用于您想要呈现的viewController。