csnewb
csnewb

Reputation: 1270

Swift - Google Firebase Authentication with Email

I am trying to run the example of Google Firebase Authentication with Email. As I tried the email example of https://github.com/firebase/quickstart-ios/blob/master/authentication/AuthenticationExampleSwift/EmailViewController.swift I get errors in the project.

My Code looks like this:

@IBAction func loginButtonTapped(_ sender: AnyObject) {
    if let email = self.userEmailTextField.text, let password = self.userPasswordTextField.text {
        showSpinner({
            // [START headless_email_auth]
            FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in
                // [START_EXCLUDE]
                self.hideSpinner({
                    if let error = error {
                        self.showMessagePrompt(error.localizedDescription)
                        return
                    }
                    self.navigationController!.popViewController(animated: true)
                })
                // [END_EXCLUDE]
            }
            // [END headless_email_auth]
        })
    } else {
        self.showMessagePrompt("email/password can't be empty")
    }
}

I get an error on showSpinner({...}) and at the very end on self.showMessagePrompt("email/password can't be empty"):

enter image description here

However, the error from the very end showMessagePrompt does not appear on self.showMessagePrompt few lines before. Maybe it has to do with my Swift Version, I tried to convert to 3, but my complete project was broken after that.

Upvotes: 1

Views: 1785

Answers (1)

Bhavin Bhadani
Bhavin Bhadani

Reputation: 22374

Because in that quickstart-ios, they uses bridging-header of UIViewController+Alerts.h file which is not implemented by you and not added by you in your project.

So one solution is to use UIViewController+Alerts.h as bridging header in your view controller or remove/modify your code something like this code..

 @IBAction func loginButtonTapped(_ sender: AnyObject) {
    if let email = self.userEmailTextField.text, let password = self.userPasswordTextField.text {
        // [START headless_email_auth]
        FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in
            // [START_EXCLUDE]

            if let error = error {
                print(error.localizedDescription)
                //show alert
                return
            }
            self.navigationController!.popViewController(animated: true)

            // [END_EXCLUDE]
        }
        // [END headless_email_auth]
    } else {
       print("email/password can't be empty")
       //show alert
    }
 }

You can find UIViewController+Alerts.h and UIViewController+Alerts.m files here

Upvotes: 1

Related Questions