首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用无法解析的标识符'FIRAuth‘(Swift 2,Firebase 3.x)

使用无法解析的标识符'FIRAuth‘(Swift 2,Firebase 3.x)
EN

Stack Overflow用户
提问于 2016-05-20 19:25:19
回答 8查看 19.4K关注 0票数 22

正在更新到新的firebase。在VC中创建了一个新的signin,一切都工作得很好,没有错误。

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

现在突然间,我的VC上到处都是未解析的标识符'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)
}

}

有人知道为什么会发生这样的事情吗?

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2016-06-03 05:42:27

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

票数 7
EN

Stack Overflow用户

发布于 2016-12-26 15:14:09

使用Swift 3Firebase 3.11.0更新2016/12/26

添加到Podfile

pod 'Firebase/Auth'

在您的位置,您需要使用Auth,只需

import Firebase

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

这个解决方案来自Google。https://firebase.google.com/docs/auth/ios/password-auth

票数 5
EN

Stack Overflow用户

发布于 2017-07-10 04:02:02

你必须添加pod ' Firebase / Auth‘在pod文件,导入Firebase和FirebaseAuth到你的控制器,现在使用认证不是FIRAuth.auth(),是Auth.auth().signInAnonymously和工作的很好。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37345465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档