2

I have one login screen, which have email, password. And in register screen after user registred they will come to login screen to login.

That time I need to check , if the user is first time user or old user. If first time user means I need to redirect them to my feedback screen. Or old user means I need to redirect them to my home screen. How to do that with firebase?

Her my code for login screen :

 @IBAction func loginWithUserNamePassword(){


    loginWithMailAndPassword((username.text?.trimWhiteSpace)!, password: (password.text?.trimWhiteSpace)!) { (user, error) in

        if error != nil{

            KRProgressHUD.dismiss()
            SCLAlertView().showError("Login Error", subTitle: error!.localizedDescription)


        }
        else {
            KRProgressHUD.dismiss()
            if user!.emailVerified{
                currentUser = user
                enableSync()
                self.callHomescreen()
            }
            else
            {
                AlertView().showError("Login Error", subTitle: "This email is has not been verified yet")
            }
        }

        }

    }

Or else in my feed back screen there are some text fields. And the model class is :

var feedbackData = [files]()

class files {
// having some string variables
}

By using this, if my data is empty in my feedback screen redirect the user to feedback screen or else redirect them to home screen. Can we do that?

Updated :

if profileData.FirstName.characters.count <= 0 {


             print("Home screen calling")

        }

        else if profileData.FirstName.characters.count > 0  {
             print("feedback screen calling")

        }

Thought of trying like this. But no use.

halfer
  • 19,824
  • 17
  • 99
  • 186
mack
  • 603
  • 2
  • 9
  • 22

1 Answers1

0

If I understand your question currectly, once user is logged in, you want to check the creation date of the use account. To do so you have two options:

  1. The server side. If you are using Firebase database just add the date of creation. Firebase documantation does not offer a method to get the creation date on the app side.

  2. The app side. User user defaults, when the user login in the first time set the date for that user. When you get to the login screen again, check for existance. I would reccomend using the user id as the key.

For example: Your user just logged in, you want to check if it the first time that he did:

if let displayName = FIRAuth.auth()?.currentUser?.displayName {
    //Make sure we have the user
    if UserDefaults.standard.bool(forKey: displayName) {
        // try to get the user default for the spacific key
        let wasConnected = UserDefaults.standard.bool(forKey: displayName)
        if wasConnected {
             print("This user was connected")
        }
    } else {
        // This user was never connected
        // We set the default to his ID
        UserDefaults.standard.set(true, forKey: displayName)
        UserDefaults.standard.synchronize()
    }
}

To use the date, I think the easiest way is to convert the date to string.

Fiddle with the code to do exactly what you want.

Community
  • 1
  • 1
Idan
  • 5,405
  • 7
  • 35
  • 52
  • due u have any example for the second choice. I m new to ios.Only i i am passing the emailid,password. But i dont know how to get the date created while registreing – mack Nov 24 '16 at 14:33
  • And also if i registered today, and what happen if i login after 10 days. How can i do with the data ? – mack Nov 24 '16 at 14:34
  • please tell me , in my post i have checked with the profile data count if it empty. But any how, it fails – mack Nov 24 '16 at 14:35