使用未解析的标识符 'FIRAuth' (Swift 2, Firebase 3.x)

Use of unresolved identifier 'FIRAuth' (Swift 2, Firebase 3.x)

正在更新到新的 Firebase。创建了一个新的登录 VC,一切正常,没有错误。

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

现在我的 VC 中突然出现错误 Use of unresolved identifier 'FIRAuth'。

我试过重新安装 pods 文件但没有成功,似乎有时如果它添加 "import 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)
}

}

有人知道为什么会这样吗?

添加 "import Firebase" 并按 cmd + B

删除此导入:

import FirebaseAuth

改为添加此语句。这对我有用。

import Firebase

MeasurementHelper.sendLoginEvent()

AppState.sharedInstance.displayName = user?.displayName ?? user?.email

AppState 是一个未识别的

在 UIViewController 中使用 Firebase 时,我确保导入 Firebase,然后清理 cache/build (cmd + shift + k),然后构建 (cmd + b)。

似乎可行,但我每次构建时都必须重做该过程。

编辑

如果第一次清洁不起作用,请继续清洁直到它起作用。不是完美的解决方案,但它有效。

我更新了 Cocoapods 和 运行 pod 更新,它解决了我所有的问题

对于未来的读者:

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

pod 'Firebase/Auth'

安装pods后,使用:

import FirebaseAuth

这就是为我解决的问题。

2016 年 12 月 26 日更新为 Swift 3Firebase 3.11.0
添加到 Podfile

pod 'Firebase/Auth'

在你的地方你需要使用Auth,只是

import Firebase

清理并重建,您将清除错误。

此解决方案引用自Google。 https://firebase.google.com/docs/auth/ios/password-auth

首先我们需要在podfile中添加firebase Auth的pod

连播 'Firebase/Auth'

然后我们需要运行终端用'pod install'

根据 firebase 文档,我们需要在我们的 viewcontroller 上添加 import firebase。但这不会解决您的 problem.you 需要添加 import FirebaseAuth。这将消除错误。

现已从 "FIRAuth" 重命名为 "Auth"

您必须在 pod 文件中添加 pod 'Firebase/Auth',将 Firebase 和 FirebaseAuth 导入您的控制器,现在使用 Auth 不是 FIRAuth.auth(),而是 Auth.auth().signInAnonymously,并且工作正常。

looks like 现在只是 "Auth" 而不是 "FIRAuth"

现在的解决方案,在 Swift 4.2 中,它只是抱怨 "Auth" 而不是 "FIRAuth" 说 "Use of unresolved identifier Auth":

注意有两个不同的导入。 import Firebaseimport FirebaseAuth

大多数时候第一个就足够了,但有时编译器会感到困惑,添加第二个版本有助于解决问题。