每当我登录苹果时,我都会收到一封null
的邮箱.请注意,显示名称不为空.此外,在try 再次登录苹果之前,我已经确保取消所有令牌,因为据我所知,苹果只提供一次邮箱,在首次注册时.以下是我在装有Firebase的安卓系统中登录苹果的代码:
OAuth提供程序:
fun appleOAuthProvider(appLanguage: String): OAuthProvider {
return OAuthProvider
.newBuilder("apple.com")
.setScopes(listOf("name", "email"))
.addCustomParameter("locale", currentLanguageLocale(appLanguage))
.build()
} //: FUN
登录:
private fun singInUser(
auth: FirebaseAuth,
context: Context,
appLanguage: String,
isSigningIn: MutableState<Boolean>,
completion: (FirebaseUser?) -> Unit
) {
auth
.startActivityForSignInWithProvider(context.getActivity(), HelperFunctions.appleOAuthProvider(appLanguage))
.addOnSuccessListener { authResult ->
Log.d("SIGN IN WITH APPLE", "activitySignIn:onSuccess:${authResult.user}")
completion(authResult.user)
} //: ON SUCCESS
.addOnFailureListener { e ->
Log.w("SIGN IN WITH APPLE", "activitySignIn:onFailure", e)
isSigningIn.value = false
completion(null)
} //: ON FAILURE
} //: FUN
登录后,我用之前获得的authResult.user
个数据收集用户的数据:
private fun collectDataFromApple(
user: FirebaseUser?,
completion: (SignInResult) -> Unit
) {
val uid = user?.uid
val email = user?.email
var firstName = separatedFullName(user?.displayName)?.get(0)
var lastName = separatedFullName(user?.displayName)?.get(1)
if (firstName.isNullOrEmpty()) {
firstName = lastName
} else if (lastName.isNullOrEmpty()){
lastName = firstName
}
completion(
SignInResult(
data =
UserData(
personalInformation = UserData.PersonalInformation(
userID = uid,
email = email,
firstName = firstName,
lastName = lastName,
imageBitmap = null,
isNewUser = true,
isEmailVerified = mutableStateOf(true),
firebaseHasData = false
),
addressInformation = UserData.AddressInformation(),
contributeStatistics = UserData.ContributeStatistics()
),
errorMessage = null
)
)
} //: FUN
由于未知原因,user?.email
返回空值.然而,firstName
和lastName
不是空的.为什么会这样呢?