本文介绍了“无效令牌";尝试使用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:
我做错了什么?谢谢
推荐答案
我也遇到了此问题.检查以下内容:
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验证电话号码时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!