使用Facebook应用程序登录,它会返回我在iOS Swift中取消的信息

时间:2019-07-03 05:41:07

标签: ios swift facebook-login

我在我的应用程序中使用Facebook登录。当我从应用程序中单击Facebook按钮时,会显示两个选项,例如使用Facebook App登录或使用电话号码或电子邮件登录。当我单击使用Facebook App的登录名时。它问我在“ Facebook”中打开?当我单击打开按钮时。它向我显示了使用继续和取消按钮的Facebook页面登录。当我单击继续按钮时,它会返回我按下的取消按钮。解决方案是什么,请提出建议。

 @IBAction func btnFacebook(_ sender: UIButton)
    {
        FBSDKLoginManager().logIn(withReadPermissions: ["email"], from: self) {(result, err) in
            if err != nil
            {
                print("Custom FB Login failed:", err!.localizedDescription)
                return
            }
            else if (result?.isCancelled)!
            {
                // Handle cancellations

                print("cancel button press")
                return
            }
            else
            {
                self.getFBUserData()
            }
            print("result\(String(describing: result))")
        }
    }



  func getFBUserData()
    {
     //, picture.type(large)
            if((FBSDKAccessToken.current()) != nil)
            {
                FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, email"]).start(completionHandler: { (connection, result, error) -> Void in
                    if (error == nil)
                    {
                        //  self.dict = result as! [String : AnyObject]
                        print(result!)
                        let email = (result as AnyObject).object(forKey: "email") as? String
                        print("email\(String(describing: email))")
                        let fullName = (result as AnyObject).object(forKey: "name") as? String
                        print("fullName\(String(describing: fullName))")
                        let id = (result as AnyObject).object(forKey: "id") as? String
                        print("id\(String(describing: id))")
    }
    }

0 个答案:

没有答案