草庐IT

iOS 链接两个 firebase 帐户

coder 2024-01-28 原文

我正在尝试链接两个 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/

有关iOS 链接两个 firebase 帐户的更多相关文章

  1. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  2. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  3. ruby-on-rails - Ruby url 到 html 链接转换 - 2

    我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.

  4. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  5. ruby - 这两个 Ruby 类初始化定义有什么区别? - 2

    我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是

  6. ruby-on-rails - Prawn - 表格单元格内的链接 - 2

    我正在尝试用Prawn生成PDF。在我的PDF模板中,我有带单元格的表格。在其中一个单元格中,我有一个电子邮件地址:cell_email=pdf.make_cell(:content=>booking.user_email,:border_width=>0)我想让电子邮件链接到“mailto”链接。我知道我可以这样链接:pdf.formatted_text([{:text=>booking.user_email,:link=>"mailto:#{booking.user_email}"}])但是将这两行组合起来(将格式化文本作为内容)不起作用:cell_email=pdf.make_c

  7. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  8. ruby - 具有两个参数的 block - 2

    我从用户Hirolau那里找到了这段代码:defsum_to_n?(a,n)a.combination(2).find{|x,y|x+y==n}enda=[1,2,3,4,5]sum_to_n?(a,9)#=>[4,5]sum_to_n?(a,11)#=>nil我如何知道何时可以将两个参数发送到预定义方法(如find)?我不清楚,因为有时它不起作用。这是重新定义的东西吗? 最佳答案 如果您查看Enumerable#find的文档,您会发现它只接受一个block参数。您可以将它发送两次的原因是因为Ruby可以方便地让您根据它的“并行赋

  9. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  10. ruby - 使用 Watir 检查错误链接 - 2

    我有一个未排序的链接列表,我将其保存在旁边,我想单击每个链接并确保它转到真实页面而不是404、500等。问题是我不知道该怎么做。是否有一些我可以检查的对象会给我http状态代码或任何东西?mylinks=Browser.ul(:id,'my_ul_id').linksmylinks.eachdo|link|link.click#needtocheckfora200statusorsomethinghere!how?Browser.backend 最佳答案 我的回答与铁皮人的想法类似。require'net/http'require'

随机推荐