swift 将iOS应用程序连接到Firebase身份验证模拟器

yftpprvb  于 2023-01-04  发布在  Swift
关注(0)|答案(2)|浏览(123)

我已经启用了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
}

当我通过验证过程创建一个新用户时,它会在live版本中创建一个用户,我在控制台中看到了这一点,但用户集合中的相应文档是在Cloud Firestore的模拟器版本中创建的。我不知道如何设置它,以便验证以及最终的存储和功能在运行时链接到模拟器。我错过了什么?

2nbm6dog

2nbm6dog1#

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

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

到我的初始化器。它现在可以进行身份验证了。

6rqinv9w

6rqinv9w2#

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
              }
            }

相关问题