在iOS上使用FirebaseUI自动登录 [英] Auto login with FirebaseUI on iOS

查看:62
本文介绍了在iOS上使用FirebaseUI自动登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注此处的文档,以使用FirebaseUI在iOS应用上显示登录屏幕. https://firebase.google.com/docs/auth/ios/firebaseui?authuser = 2

I'm following the documentation here to use FirebaseUI to show sign-in screens on an iOS app. https://firebase.google.com/docs/auth/ios/firebaseui?authuser=2

如何在用户登录后自动登录,而不必每次都显示此UI?

How do I automatically sign-in a user after they have already signed-in before without having to present this UI each time?

推荐答案

Firebase Auth SDK将在应用程序启动之间保留登录信息.但是,在应用启动时,登录的用户不会立即可用.您应该做的是使用

The Firebase Auth SDK will persist login information between app launches. However, the signed in user isn't available immediately when the app launches. What you should do is establish an auth state listener using addStateDidChangeListener to find out when the an authenticated is definitely signed in or not.

可以在其他问题中看到这种模式:通过iOS中的侦听器检查Firebase当前登录的用户

This pattern can be seen in this other question: Checking Firebase current signed-in user via Listener in iOS

FIRAuth.auth()?.addStateDidChangeListener { auth, user in
  if let user = user {
    // User is signed in. Show home screen
  } else {
    // No User is signed in. Show user the login screen
  }
}

第一次知道用户状态时将调用该块,因此您可以使用它来决定是否预设登录屏幕.

The block will be invoked when the state of the user is first known, so you can use that to decide then whether or not to preset the sign-in screen.

这篇关于在iOS上使用FirebaseUI自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆