在展示应用的主视图控制器之前,我想检查用户是否仍有有效会话。我使用最新的Firebase API。我想如果我使用旧版,我将能够知道这一点。
以下是我目前所做的:
- 我在Firebase的Slack社区上发布了我的问题,没有人回答。我找到了这个,但这是针对Android的:https://groups.google.com/forum/?hl=el#!topic/firebase-talk/4HdhDvVRqHc
- 我试着阅读iOS版Firebase的文档,但我似乎无法理解它:https://firebase.google.com/docs/reference/ios/firebaseauth/interface_f_i_r_auth
我试着像这样输入Xcode:
FIRApp().currentUser()
FIRUser().getCurrentUser()
但我似乎找不到getCurrentUser函数。
8条答案
按热度按时间puruo6ea1#
对于更新的SDK
fbcarpbf2#
最新Firebase SDK的解决方案-DOCS
Swift 3中的解决方案
其中
switchStoryboard()
为Source
xxslljrj3#
Swift 4中的解决方案
vjrehmav4#
cngwdvgl5#
虽然您 * 可以 * 看到是否有这样的用户使用
Auth.auth().currentUser
,但这只会告诉您是否有用户经过身份验证,而不管该用户的帐户是否仍然存在或有效。完整解决方案
真实的的解决方案应该是使用
Firebase
的重新身份验证:这可确保(在启动应用程序时)之前登录/认证的用户 * 实际上*仍然通过Firebase进行认证。
hfwmuf9z6#
来源:https://www.raywenderlich.com/139322/firebase-tutorial-getting-started-2
yx2lnoni7#
目标c解决方案是(iOS 11.4):
kpbwa7wx8#
所有提供的答案只能在
currentUser
上检查。但您可以通过简单的用户重新加载来检查auth会话,如下所示: