iOS Firebase sign in with apple displayName 为空问题

Firebase Apple 登录就不说了,可直接查看Firebase 文档。
目前存在的问题是,Apple 使用 Firebase 登录后,用户信息里的用户名为空,
所以通过下面代码来进行处理,同步用户名到 Firebase。

// Sign in with Firebase.
Auth.auth().signIn(with: credential) { (authResult, error) in
    if let error = error {
        // Error. If error.code == .MissingOrInvalidNonce, make sure
        // you're sending the SHA256-hashed nonce as a hex string with
        // your request to Apple
        return
    }
    
    guard let user = authResult?.user else { return }
    if let fullName = appleIDCredential.fullName,
       let givenName = fullName.givenName,
       let familyName = fullName.familyName {
        let changeRequest = user.createProfileChangeRequest()
        changeRequest.displayName = givenName + familyName
        changeRequest.commitChanges(completion: { _ in
            Network.share.googleLogin(user: user)
        })
    }
    // 处理 user 信息,如登录或者同步
}

你可能感兴趣的:(iOS Firebase sign in with apple displayName 为空问题)