[英]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.