Firebase profileChangeRequest未被调用

时间:2016-07-30 23:31:21

标签: swift facebook firebase fbsdk

我试图在我的Facebook用户登录后为displayName变量执行profileChangeRequest并为Firebase兑换一个Facebook令牌,但是当我去显示displayName时,它不会改变。在下面的示例中,显示名称打印出Facebook用户的名称,但不打印“Hometown”(仅作为示例)。关于为什么profileChangeRequest.commitChangesWithCompletion似乎不起作用的想法?我的代码在

之下

谢谢,

雅各

代码:

var fbloginresult : FBSDKLoginManagerLoginResult = result
        if(fbloginresult.grantedPermissions.contains("email"))
        {

            let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
            FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
                if let error = error {

                    let coolMes: String! = String(error.userInfo["NSLocalizedDescription"]!)

                    let Alert:UIAlertView = UIAlertView(title: "Warning", message: coolMes!, delegate: self, cancelButtonTitle: "Ok")

                    Alert.show()
                }

                else{

                    user?.profileChangeRequest().displayName = "Hometown"
                    user?.profileChangeRequest().commitChangesWithCompletion({error in

                        if let error = error{

                        }

                        else{
                            print(user?.displayName)  // this prints the actual display name, NOT hometown, as expected

                            let CreateView = self.storyboard?.instantiateViewControllerWithIdentifier("NavController") as! UITabBarController
                            self.presentViewController(CreateView, animated: true, completion: nil)
                        }

                        })




                }
            }

0 个答案:

没有答案