簡體   English   中英

將 iOS 應用程序連接到 Firebase 身份驗證模擬器

[英]Connect iOS app to Firebase Authentication Emulator

我啟用了 Firebase 模擬器套件並鏈接到我的測試項目之一。 當我啟動模擬器時,我在終端中看到以下內容。

終端輸出

這是一個SwiftUI應用程序,它目前使用身份驗證和 Firestore。 當我配置 Firestore 時,我會在初始化應用程序時執行以下操作:

init() {
    FirebaseApp.configure()
    let settings = Firestore.firestore().settings
    settings.host = "localhost:8080"
    settings.isPersistenceEnabled = false
    settings.isSSLEnabled = false
    Firestore.firestore().settings = settings
}

當我通過身份驗證過程創建一個新用戶時,它會在實時版本中創建一個用戶,我會在我的控制台中看到它,但用戶集合中的相應文檔是在 Cloud Firestore 的模擬器版本中創建的。 我無法弄清楚如何設置它以便身份驗證以及最終存儲和功能在我運行時鏈接到模擬器。 我錯過了什么?

我找到了答案。 我需要補充:

 Auth.auth().useEmulator(withHost:"localhost", port:9099)

到我的初始化程序。 它現在正在用於身份驗證。

我到處搜索以獲得相同的答案...

但是,當我實現它時,無論我把它放在哪里,我都會收到 Xcode 錯誤響應。

響應:“'Auth' 類型的值沒有成員 'useEmulator'

但它確實......我直接從代碼完成中選擇它。

我已經根據當前的 Firebase 文檔安裝了這些 pod: pod 'Firebase/Analytics' pod 'Firebase/Auth' pod 'Firebase/Firestore' pod 'FirebaseFirestoreSwift'

在我嘗試使用此行的任何文件上,我都導入了這些依賴項: import FirebaseAuth import FirebaseFirestore import FirebaseFirestoreSwift

我錯過了什么?

    import SwiftUI
    import FirebaseCore
    import FirebaseAuth
    
    class AppDelegate: NSObject, UIApplicationDelegate {
              func application(_ application: UIApplication,
                               didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

        FirebaseApp.configure()
    
        //This line here 
    
        Auth.auth().useEmulator(withHost:"localhost", port:9099)
            
            
                return true
              }
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM