gpt4 book ai didi

ios - Firebase 身份验证 : Phone number authentication in Swift

转载 作者:行者123 更新时间:2023-11-29 05:26:09 25 4
gpt4 key购买 nike

我的输出控制台中正在打印本地化描述:“无法获取验证:可选(“如果禁用应用程序委托(delegate)调整,则 UIApplicationDelegate 收到的远程通知需要转发到 FIRAuth\的 canHandleNotificaton:方法。” )”

尽管如此,我在手机中收到了 OTP 以及用于验证的验证码,但它不会将我带到下一页,我们需要在该页面中验证收到的 OTP。

我的代码在收到 OTP 之前工作正常,但之后它显示我需要输入我的号码的同一页面。

我的 viewcontroller.swift 有以下代码:

    @IBAction func mobileNumberSubmitButton(_ sender: Any) {

guard let phonenumber = mobileNumberText.text else {return}

PhoneAuthProvider.provider().verifyPhoneNumber(phonenumber, uiDelegate: nil) {(verificationid, error) in
if error == nil{
print(verificationid)
guard let verify = verificationid else {return}
self.userdefault.set("verify", forKey: "verifyID")
self.userdefault.synchronize()
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "OTPVerificationID") as! OTPVerificationViewController
viewController.verifyid = verificationid!
self.navigationController?.pushViewController(viewController, animated: true)

}else{
print("unable to get verification:", error?.localizedDescription)
}
}



}

我的 otpverificationviewcontroller.swift 有以下代码:

     class OTPVerificationViewController: UIViewController { 

var verifyid : String = ""
let userdefault = UserDefaults()

@IBOutlet weak var OTPVerifyCode: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

let valust = self.userdefault.dictionary(forKey: "verifyID")
print(verifyid)

}

@IBAction func verificationSubmitButton(_ sender: Any) {

guard let verifycode = OTPVerifyCode.text else {return}
let credentials = PhoneAuthProvider.provider().credential(withVerificationID: verifyid, verificationCode: verifycode)
Auth.auth().signInAndRetrieveData(with: credentials) { (result, error) in
if error == nil {
if let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ServiceViewControllerID") as? ServiceViewController {

UIApplication.shared.keyWindow?.rootViewController = viewController
self.dismiss(animated: true, completion: nil)
}
} else{
print(error?.localizedDescription)
}
}
}

}

我希望 mobileNumberSubmitButton 操作推送 otpverification 页面以验证 OTPcode。

有人可以给我一些解决方案吗?

最佳答案

在主线程上执行如下操作:

DispatchQueue.main.async{
let viewController =
self.storyboard?.instantiateViewController(withIdentifier: "OTPVerificationID") as! OTPVerificationViewController
viewController.verifyid = verificationid!
self.navigationController?.pushViewController(viewController, animated: true)
}

关于ios - Firebase 身份验证 : Phone number authentication in Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58154367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com