我尝试从 firebase 设置 PhoneAuth,但我是新的,我只是不知道为什么会这样
这是部分代码
let credential: PhoneAuthCredential = PhoneAuthProvider.provider().credential(withVerificationID: defaults.string(forKey: "AuthVID")!, verificationCode: self.codeInputField.text!)
我认为问题出在这里,但我不知道如何解决
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)
}
关于ios - FireBase PhoneAuth 线程 1 : Fatal error: Unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49746323/