如何检测用户是否已通过Firebase和Facebook,电子邮件或Google通过Swift使用我的应用程序登录了我的应用程序 [英] How to detect if a user has signed in to my app using Firebase with Facebook, email, or Google using Swift

查看:38
本文介绍了如何检测用户是否已通过Firebase和Facebook,电子邮件或Google通过Swift使用我的应用程序登录了我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测用户是否使用Facebook或电子邮件等登录了

I want to detect if a user has signed in using Facebook or email, etc...

我找到了Android的答案,但是我正在使用Swift for iOS进行编程,并且不确定如何完全翻译代码.

I found an answer for Android, but I am programming in Swift for iOS and I am not sure how to translate the code entirely.

android/java代码为:

The android/java code is :

for (UserInfo user:FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {
if (user.getProviderId().equals("facebook.com")) {
System.out.println("User is signed in with Facebook");
  }
}

我尝试翻译它,但是我似乎无法弄清楚如何访问这些值.我一直在获取内存地址.

I have tried to translate it, but I can't seem to figure out how to access the values. I keep getting a memory address instead.

这是我的快速代码:

let authenticatedWith = FIRAuth.auth()?.currentUser?.providerData

推荐答案

根据 docs providerData FIRUserInfo 结构的数组.

您发布的Android代码的(大部分)等效的Swift代码如下:

The (mostly) equivalent Swift code for the Android code you posted looks like this:

if let providerData = FIRAuth.auth()?.currentUser?.providerData {
    for userInfo in providerData {
        switch userInfo.providerID {
        case "facebook.com":
            print("user is signed in with facebook")
        default:
            print("user is signed in with \(userInfo.providerID)")
    }
}

请注意, providerID 属性也可以直接在 currentUser 属性返回的 FIRUser 结构上使用,因此您可以做到这一点:

Note that the providerID property is also available directly on the FIRUser structure returned by the currentUser property, so you may be able to just do this:

if let providerID = FIRAuth.auth()?.currentUser?.providerID {
    switch providerID {
    default:
        print("user is signed in with \(providerID)")
    }
}

这篇关于如何检测用户是否已通过Firebase和Facebook,电子邮件或Google通过Swift使用我的应用程序登录了我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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