ios - Firebase iOS 电话身份验证:无法验证电话号码
问题描述
我正在尝试使用 Firebase 和电话号码在 iOS 上进行身份验证。
我通过打印语句发现的问题是 SubmitPhoneNumber()。它命中“我们发现错误”打印语句,并且报告的错误是
FIRAuthErrorUserInfoNameKey=ERROR_INVALID_PHONE_NUMBER 以及
FIRAuthErrorUserInfoNameKey=ERROR_WEB_CONTEXT_ALREADY_PRESENTED
我不知道该怎么做或如何解决这个问题。我传递的电话号码格式是“+[国家代码]1234567890”
import SwiftUI
import Firebase
struct VerifyPhoneView: View {
private var phoneNumber: String = ""
@State private var verificationID: String = ""
@State private var verificationCode: String = ""
@State private var loginSuccesful: Bool = false
@EnvironmentObject var ls: LoginStatus
init(phoneNumber: String) {
self.phoneNumber = phoneNumber
submitPhoneNumber()
}
var body: some View {
ZStack {
Text("My code is")
TextField("Enter code", text: $verificationCode)
Button(action: {
self.submitVerificationCode()
}) {
Text("Continue")
}
}
}
func submitPhoneNumber() {
print("the submitPhoneNumber method was called")
PhoneAuthProvider.provider().verifyPhoneNumber("+1" + phoneNumber, uiDelegate: nil) { (verificationID, error) in
if error != nil {
print("we found an error")
print(error?.localizedDescription)
return
}
else {
print("we did not find an error")
print(verificationID!)
self.verificationID = verificationID!
}
}
}
func submitVerificationCode() {
print ("222 verificationID is " + self.verificationID)
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: self.verificationID,
verificationCode: self.verificationCode)
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
print(error.debugDescription)
return
}
// User is signed in
print("User signed in succesfully")
}
}
}
解决方案
推荐阅读
- java - 店铺一览
成二维 Object[][] - plsql - 可以使用 NLS_date 格式从不同会话中获得相同的结果吗?
- java - 允许为 Hibernate 验证的子对象覆盖/设置约束验证
- jquery - 尝试在 if 语句中使用输入字段中的数字时获取 NaN
- php - Woocommerce Paypal REST api 与 React JS 的集成
- c# - TCPClient 向 TCPListener 发送消息后超时
- javascript - 如何显式共享 NPM 包的文件部分?
- django - 注释相关的相关过滤对象的计数
- sms - 使用 RingCentral 安排 SMS 消息
- javascript - 如何在子组件中使用 formControlName 然后在父组件中获取它的值?