如何在通过firebaseAuth进行身份验证时将Gmail帐户的名字和姓氏发布到firebase。如何获取用户配置文件?从Gmail帐户向Firebase发布名字和姓氏
我创建用户在火力上GIDGoogleUser ..和使用:
let authentication = user.authentication
我上同一类东西,我大概可以使用发现,但我需要的建议是它做的正确方法,以及如何从中获取名字和姓氏..?
let profile = user.profile
我AppDelegate.swift
import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
UIApplication.shared.statusBarStyle = .lightContent
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print(error.localizedDescription)
return
}
let authentication = user.authentication
let credential = GoogleAuthProvider.credential(withIDToken (authentication?.idToken)!,accessToken: (authentication?.accessToken)!)
Auth.auth().signIn(with: credential) { (user, error) in
if error != nil {
return
} else {
let registrationReq = FirebaseRegistrationLoginRequests()
registrationReq.checkIfCreateOrGetUser(user: user!)
}
}
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user:GIDGoogleUser!, withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
debugPrint(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
}