菜鸟教程小白 发表于 2022-12-11 18:43:37

ios - 集成 FirebasePhoneAuthUI 以进行电话号码身份验证


                                            <p><p>我们正在使用没有 Cocopods 的 firebase SDK,在集成 firebase 电话身份验证时,我们遇到了崩溃:- </p>

<blockquote>
<p>Error:- 2017-09-18 19:30:46.123775+0530 NewFireBaseDummy
<strong>* Terminating app due to uncaught exception &#39;NSInternalInconsistencyException&#39;, reason: &#39;Could not load NIB in
bundle: &#39;NSBundle

(loaded)&#39; with name &#39;FUIPhoneEntryViewController&#39;&#39;
*</strong> First throw call stack: (0x1901aefe0 0x18ec10538 0x1901aef28 0x1967e6600 0x1966472d4 0x19641146c 0x1962dfb68 0x1962dfa9c
0x1000f8174 0x1000f3a38 0x1000f39a4 0x1000f1140 0x1001066b8
0x10008bed4 0x10008b9c8 0x10008bb04 0x1000d0754 0x1000d0ad8
0x100c71a50 0x100c71a10 0x100c76b78 0x19015d0c8 0x19015ace4
0x19008ada4 0x191af4074 0x196345058 0x10008dcb0 0x18f09959c)
libc++abi.dylib: terminating with uncaught exception of type
NSException</p>
</blockquote>

<pre><code>import UIKit
import Firebase
import FirebaseAuthUI
import FirebasePhoneAuthUI

class ViewController: UIViewController, FUIAuthDelegate {

fileprivate(set) var auth:Auth?
fileprivate(set) var authUI: FUIAuth? //only set internally but get externally
fileprivate(set) var authStateListenerHandle: AuthStateDidChangeListenerHandle?

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
    self.auth = Auth.auth()
    self.authUI = FUIAuth.defaultAuthUI()
    self.authUI?.delegate = self
    self.authUI?.providers =


    self.authStateListenerHandle = self.auth?.addStateDidChangeListener { (auth, user) in
      guard user != nil else {
            self.loginAction(sender: self)
            return
      }

    }


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func loginAction(sender:AnyObject){
    //direct open the auth page
    let provider = self.authUI?.providers.first as! FUIPhoneAuth;
    provider.signIn(withPresenting: self);
}

func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
    guard let authError = error else { return }

    let errorCode = UInt((authError as NSError).code)

    switch errorCode {
    case FUIAuthErrorCode.userCancelledSignIn.rawValue:
      print(&#34;User cancelled sign-in&#34;);
      break

    default:
      let detailedError = (authError as NSError).userInfo ?? authError
      print(&#34;Login error: \((detailedError as! NSError).localizedDescription)&#34;);
    }
}

}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我不确定你的错误,但也许你错过了对 PhoneAuth 非常重要的东西。
也许您可以尝试按照 YouTube 上的本教程来弄清楚:<a href="https://www.youtube.com/watch?v=bujGsqBo4xk" rel="noreferrer noopener nofollow">https://www.youtube.com/watch?v=bujGsqBo4xk</a>
它逐步描述了如何使用 Firebase 进行 PhoneAuth
希望对你有帮助</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 集成 FirebasePhoneAuthUI 以进行电话号码身份验证,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/46281503/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/46281503/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 集成 FirebasePhoneAuthUI 以进行电话号码身份验证