gpt4 book ai didi

iOS 链接两个 firebase 帐户

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:47 27 4
gpt4 key购买 nike

我正在尝试链接两个 firebase 帐户,通常用户会使用社交媒体或电子邮件或 anonmus 帐户登录,然后用户会使用电话登录。我需要链接这两个帐户。

父 View

将调用父 View 中的函数以使用电话号码注册

class welcomeView: UIViewController, FUIAuthDelegate {

//stores current user
var previosUser = FIRUser()


override func viewDidLoad() {
super.viewDidLoad()
if let user = Auth.auth().currentUser {
previosUser = user
}else{
Auth.auth().signInAnonymously() { (user, error) in

if error != nil {
//handle error
}
previosUser = user!
}
}

}






func signUpWithPhone(){
let vc = signUpWithPhoneView()
vc.authUI?.delegate = self
vc.auth?.languageCode = "ar"
self.present(vc, animated: true)

}


}

在 subview (signUpWithPhoneView) 中,我展示了 FUIPhoneAuth

phoneProvider.signIn(withPresenting: self)

subview

import UIKit
import FirebaseAuthUI
import FirebasePhoneAuthUI

class signUpWithPhoneView: UIViewController {

fileprivate(set) var authUI = FUIAuth.defaultAuthUI()
var didload = false

override func viewDidLoad() {
super.viewDidLoad()
}


override func viewWillAppear(_ animated: Bool) {
if !didload { // stops from looping
didload = !didload

guard let authUI = self.authUI else {return}
let phoneProvider = FUIPhoneAuth.init(authUI: authUI)
self.authUI?.providers = [phoneProvider]
>> phoneProvider.signIn(withPresenting: self)

}
}


}

当用户登录时, subview 将自动关闭,我有 didSignInWith 函数将在父 View 中调用。我需要关联之前的用户账号和用户手机账号

父 View

    func authUI(_ authUI: FUIAuth, didSignInWith user: FirebaseAuth.User?, error: Error?) {

if let user = user{

// link the the two accounts

}else{

}

}

我尝试使用

链接
        let provider = PhoneAuthProvider.provider(auth: authUI.auth!)
let credential = PhoneAuthProvider.credential(provider)


previosUser.link(with: credential, completion: { (user, error) in
if error != nil {
print("this is linking two acounts error : " , error)
}
})

但是凭证有错误

...previosUser.link(with: *credential*, completion: ...

Cannot convert value of type '(String, String) -> PhoneAuthCredential' to expected 
argument type 'AuthCredential'

任何帮助将不胜感激谢谢

最佳答案

您正在使用 authUI.auth 获取提供程序,然后不使用它来获取凭据,并且您当前正在使用实例方法 credential 的静态引用。

实例方法本身采用两个字符串并返回一个 AuthCredential,这就是您看到 (String, String) -> AuthCredential 的原因。您必须使用必须从用户那里收集的验证 ID 和代码来创建凭据。

guard let auth = authUI.auth else { return }

let provider = PhoneAuthProvider.provider(auth: auth)
let credential = provider.credential(
withVerificationID: "XXXXXXXXXXXX",
verificationCode: "XXXXXX"
)

// ...

关于iOS 链接两个 firebase 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46997670/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com