gpt4 book ai didi

ios - FireBase PhoneAuth 线程 1 : Fatal error: Unexpectedly found nil while unwrapping an Optional value

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:03:37 24 4
gpt4 key购买 nike

我尝试从 firebase 设置 PhoneAuth,但我是新的,我只是不知道为什么会这样

这是部分代码

 let credential: PhoneAuthCredential = PhoneAuthProvider.provider().credential(withVerificationID: defaults.string(forKey: "AuthVID")!, verificationCode: self.codeInputField.text!)

Here is error

What Xcode shows about error

我认为问题出在这里,但我不知道如何解决

Printing description of credential:(PhoneAuthCredential) credential = <variable not available>

谢谢

最佳答案

问题似乎出在下一行,因为您正在强行解包可选。

let credential: PhoneAuthCredential = PhoneAuthProvider.provider().credential(withVerificationID: defaults.string(forKey: "AuthVID")!, verificationCode: self.codeInputField.text!)

原因

可能是你的 AuthVID 是 nil ,(UserDefault 中没有 String with key AuthID )或者 self.codeInputField 没有连接到 socket

解决方案

提供默认值或使用可选链接。

if let strAuthVID = defaults.string(forKey: "AuthVID"), let code = self.codeInputField.text
{
let credential: PhoneAuthCredential = PhoneAuthProvider.provider().credential(withVerificationID:strAuthVID, verificationCode: code)

}

enter image description here

关于ios - FireBase PhoneAuth 线程 1 : Fatal error: Unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49746323/

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