简体   繁体   中英

Undeclared Identifier FIRAuth

I am a beginner in iOS and fire base.

  • I installed firebase cocoa pods.
  • Imported firebase.h in my loginViewcontroller.h
  • Added pod 'Firebase/Core', pod 'Firebase/Database', pod 'Firebase/Auth'.

I am migrating from parse to firebase, I added following fire base authentication code in my loginViewController.m .

[[FIRAuth auth] createUserWithEmail:email password:password completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { // ... }];

But it shows an error called use of undeclared identifier FIRAuth . Please help.

您应该导入FirebaseAuth。

@import FirebaseAuth;

Check if,

1) pod 'Firebase/Auth' is present or not

2) In app delegate have you configured using the below method

@import Firebase;
// Use Firebase library to configure APIs
[FIRApp configure];

Try this i hope it would be helpful!But it's in swift

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]? = [:]) -> Bool {
    UIApplication.shared.statusBarStyle = .lightContent
    FIRApp.configure()

    FIRDatabase.database().persistenceEnabled = true
    return true
  }

After that you can use it like this!

     @IBAction func signUpDidTouch(_ sender: AnyObject)
  {
    let alert = UIAlertController(title: "Register",message: "Register",preferredStyle: .alert)

    let saveAction = UIAlertAction(title: "Save",style: .default) { action in

      let emailField = alert.textFields![0]
      let passwordField = alert.textFields![1]

      FIRAuth.auth()?.createUser(withEmail: emailField.text!, password: passwordField.text!, completion: { (user, error) in

        if error == nil{
          FIRAuth.auth()?.signIn(withEmail: self.textFieldLoginEmail.text!, password: self.textFieldLoginPassword.text!, completion: nil)
        }
      })

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM