“无效令牌";尝试使用Firebase验证电话号码时 [英] "Invalid Token" when trying to authenticate phone number using firebase
问题描述
这是我的代码:
import FirebaseAuth
class AuthPhoneNum {
static func getPhoneNum(phoneNumber: String) {
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
if let error = error {
print(error)
return
}
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
}
}
static func verify(verificationCode: String?) {
guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
if verificationCode != nil {
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationID,
verificationCode: verificationCode!)
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
print(error)
return
}
}
} else {
print("No verification code")
}
}
}
这是控制台输出的内容:
This is what the console prints out:
错误域= FIRAuthErrorDomain代码= 17048无效令牌." UserInfo = {NSLocalizedDescription =无效的令牌., error_name = INVALID_APP_CREDENTIAL}
Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token." UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL}
我做错了什么?谢谢
推荐答案
我也遇到了此问题.检查以下内容:
I was also experiencing this problem. Checked the following:
- 更正捆绑包ID
- 更正Google-Info.plist
- 更正
aps-environment
值 - 调用
auth.setAPNStoken
时更正APNS令牌类型(.unknown
用于自动检测)
- Correct bundle Id
- Correct Google-Info.plist
- Correct
aps-environment
value - Correct APNS token type when calling
auth.setAPNStoken
(.unknown
for auto detect)
直到在Firebase应用程序设置中我什么都没有帮助,我上载了APNS身份验证密钥(p8)而不是证书-我以前仅将这些证书用于推送通知,并且一切正常,但是对于电话号码通知出了错.
Nothing helped until in Firebase app settings I uploaded the APNS authentication key (p8) instead of certificates - I used those certificates before for push notifications only and everything was working fine but for phone number notifications something went wrong.
这篇关于“无效令牌";尝试使用Firebase验证电话号码时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!