【问题标题】:How to check whether the user is new user or old user如何判断用户是新用户还是老用户
【发布时间】:2016-11-24 13:25:57
【问题描述】:

我有一个登录屏幕,其中有电子邮件、密码。并在用户注册后的注册屏幕中,他们将来到登录屏幕进行登录。

那个时候我需要检查用户是第一次使用还是老用户。如果第一次用户意味着我需要将他们重定向到我的反馈屏幕。或者老用户意味着我需要将他们重定向到我的主屏幕。如何用 Firebase 做到这一点?

她的登录屏幕代码:

 @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")
            }
        }

        }

    }

否则在我的反馈屏幕中有一些文本字段。模型类是:

var feedbackData = [files]()

class files {
// having some string variables
}

通过使用它,如果我的反馈屏幕中的数据为空,则将用户重定向到反馈屏幕,或者将他们重定向到主屏幕。我们可以这样做吗?

更新:

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


             print("Home screen calling")

        }

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

        }

想过这样尝试。但是没有用。

【问题讨论】:

    标签: ios swift firebase firebase-authentication


    【解决方案1】:

    如果我正确理解你的问题,一旦用户登录,你想检查使用帐户的创建日期。为此,您有两种选择:

    1. 服务器端。如果您使用 Firebase 数据库,只需添加创建日期。 Firebase documantation 不提供在应用端获取创建日期的方法。

    2. 应用程序端。用户用户默认,当用户第一次登录时为该用户设置日期。当您再次进入登录屏幕时,请检查是否存在。我建议使用用户 ID 作为密钥。

    例如: 您的用户刚刚登录,您想检查他是否是第一次登录:

    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()
        }
    }
    

    要使用日期,我认为最简单的方法是convert the date to string

    修改代码来做你想做的事。

    【讨论】:

    • 因为你有任何第二选择的例子。我是 ios 的新手。只有我在传递电子邮件 ID、密码。但我不知道如何获取注册时创建的日期
    • 如果我今天注册,如果我在 10 天后登录会发生什么。我该如何处理数据?
    • 请告诉我,在我的帖子中,我检查了配置文件数据计数是否为空。但无论如何,它失败了
    猜你喜欢
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 2019-08-17
    • 2015-11-15
    • 2021-08-15
    • 2018-07-05
    相关资源
    最近更新 更多