XServer.app Google Sing in:在 iOS Swift 中更新用户数据

问题描述

我正在构建一个 iOS 应用,需要允许我的用户使用 XServer

登录 Google

我已经下载并安装了 SDK,在我的 Google Cloud Platform 上创建了 OAuth 凭证,这是我目前的代码:

import GoogleSignIn

class GLogin: UIViewController,GIDSignInDelegate {

    @IBOutlet weak var googleButton: UIButton!
    var googleSignIn = GIDSignIn.sharedInstance()
    

    // Google Sign in button
    @IBAction func gSignInButton(_ sender: Any) {
        googleSignIn?.presentingViewController = self
        googleSignIn?.clientID = "My_Google_OAuth_Id"
        googleSignIn?.delegate = self
        googleSignIn?.signIn()
    }

}


func sign(_ signIn: GIDSignIn!,didSignInFor user: GIDGoogleUser!,withError error: Error!) {
           guard let user = user else {
               print("Google login cancelled.")
               return
           }
           
           // Get User info
           let password = user.userID ?? ""
           let firstName = user.profile.givenName ?? ""
           let lastName = user.profile.familyName ?? ""
           let email = user.profile.email ?? password + "@google.com"
           let profilePicURL = user.profile.imageURL(withDimension: 150)?.absoluteString
           let username = firstName.lowercased() + lastName.lowercased()
           let fullName = firstName + " " + lastName
           
           self.XSSignUp(username: username,password: password,email: email,signInWith: "google") { (results,e) in
           if error == nil {
               
               // I don't know what to do here...

           } else { DispatchQueue.main.async { print(e!) }
       }}// ./ XSSignUp()

    }
       
    func sign(_ signIn: GIDSignIn!,didDisconnectWith user: GIDGoogleUser!,withError error: Error!) {
           // Call your backend server to delete user's info after they requested to delete their account
    }

所以,我可以成功检索到一个谷歌用户的数据,也可以在数据库中注册该用户,但是我不知道如何更新它的全名和头像,所以执行上面的代码后那些列都是空的.

我错过了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)