How to determine if a user was connected to my application using Firebase with Facebook, email or Google using Swift

I want to determine if a user has subscribed to using Facebook or email, etc.

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

Android / java code:

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

I tried to translate it, but I cannot figure out how to access the values. Instead, I get the memory address.

Here is my quick code:

let authenticatedWith = FIRAuth.auth()?.currentUser?.providerData
+4
source share
1 answer

According to docs providerData is an array of structures FIRUserInfo.

( ) Swift Android, , :

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 FIRUser, currentUser, :

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

Source: https://habr.com/ru/post/1651894/


All Articles