ios – 使用未解析的标识符“FIRAuth”(Swift 2,Firebase 3.x)

前端之家收集整理的这篇文章主要介绍了ios – 使用未解析的标识符“FIRAuth”(Swift 2,Firebase 3.x)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
更新到新的firebase.创建一个新的登录VC,一切都没有错误的工作正常.

试图复制这个新的教程:https://codelabs.developers.google.com/codelabs/firebase-ios-swift/index.html?index=..%2F..%2Findex#0

现在突然间我得到错误使用未解决的标识符’FIRAuth’在我的VC.

我已经尝试重新安装pods文件,没有任何运气,似乎有时如果它添加“导入Firebase”,然后删除它的应用程序将编译,似乎没有韵律或理由为什么它有时工作其他时候没有:

这是我的代码

import UIKit
import FirebaseAuth


class SignInViewController: UIViewController {

@IBOutlet weak var emailField: UITextField!

@IBOutlet weak var passwordField: UITextField!

override func viewDidAppear(animated: Bool) {
    if let user = FIRAuth.auth()?.currentUser { //error here 
        self.signedIn(user)
    }
}

@IBAction func didTapSignIn(sender: AnyObject) {
    // Sign In with credentials.
    let email = emailField.text
    let password = passwordField.text
    FIRAuth.auth()?.signInWithEmail(email!,password: password!) { //error here (user,error) in
        if let error = error {
            print(error.localizedDescription)
            return
        }
        self.signedIn(user!)
    }
}
@IBAction func didTapSignUp(sender: AnyObject) {
    let email = emailField.text
    let password = passwordField.text
    FIRAuth.auth()?.createUserWithEmail(email!,password: password!) { // error here(user,error) in
        if let error = error {
            print(error.localizedDescription)
            return
        }
        self.setDisplayName(user!)
    }
}

func setDisplayName(user: FIRUser) {
    let changeRequest = user.profileChangeRequest()
    changeRequest.displayName = user.email!.componentsSeparatedByString("@")[0]
    changeRequest.commitChangesWithCompletion(){ (error) in
        if let error = error {
            print(error.localizedDescription)
            return
        }
        self.signedIn(FIRAuth.auth()?.currentUser) //error here
    }
}

@IBAction func didRequestPasswordReset(sender: AnyObject) {
    let prompt = UIAlertController.init(title: nil,message: "Email:",preferredStyle: UIAlertControllerStyle.Alert)
    let okAction = UIAlertAction.init(title: "OK",style: UIAlertActionStyle.Default) { (action) in
        let userInput = prompt.textFields![0].text
        if (userInput!.isEmpty) {
            return
        }
        FIRAuth.auth()?.sendPasswordResetWithEmail(userInput!) { //error here (error) in
            if let error = error {
                print(error.localizedDescription)
                return
            }
        }
    }
    prompt.addTextFieldWithConfigurationHandler(nil)
    prompt.addAction(okAction)
    presentViewController(prompt,animated: true,completion: nil);
}

func signedIn(user: FIRUser?) {
    MeasurementHelper.sendLoginEvent()

    AppState.sharedInstance.displayName = user?.displayName ?? user?.email
    AppState.sharedInstance.photoUrl = user?.photoURL
    AppState.sharedInstance.signedIn = true
    NSNotificationCenter.defaultCenter().postNotificationName(Constants.NotificationKeys.SignedIn,object: nil,userInfo: nil)
   // performSegueWithIdentifier(Constants.Segues.SignInToFp,sender: nil)
}

}

有没有人知道为什么会发生这种情况?

解决方法

对于未来的读者:

确保在您的Podfile中包含以下内容

pod’Firebase / Auth’

安装pod后,请使用:

导入FirebaseAuth

这是为我解决的.

原文链接:https://www.f2er.com/iOS/336812.html

猜你在找的iOS相关文章