集成FirebasePhoneAuthUI以进行电话号码验证

时间:2017-09-18 14:12:59

标签: ios swift firebase firebase-authentication

我们正在使用没有Cocopods的firebase SDK,在集成firebase手机身份验证时,我们正在崩溃: -

  

错误: - 2017-09-18 19:30:46.123775 + 0530 NewFireBaseDummy [2174:475150]    *由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法加载NIB   捆绑:'NSBundle      (加载)'名称'FUIPhoneEntryViewController''   * 第一次抛出调用堆栈:(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:以未捕获的类型异常终止   NSException

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 = [FUIPhoneAuth(authUI: self.authUI!)]


    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("User cancelled sign-in");
        break

    default:
        let detailedError = (authError as NSError).userInfo[NSUnderlyingErrorKey] ?? authError
        print("Login error: \((detailedError as! NSError).localizedDescription)");
    }
}

}

1 个答案:

答案 0 :(得分:0)

我不确定您的错误,但也许您错过了对PhoneAuth非常重要的事情。 也许您可以尝试通过YouTube关注本教程来解决这个问题:https://www.youtube.com/watch?v=bujGsqBo4xk 它逐步介绍了如何使用Firebase制作PhoneAuth 希望它有所帮助