gpt4 book ai didi

ios - 如何通过 Swift 连接到本地 Firebase 服务器?

转载 作者:搜寻专家 更新时间:2023-10-31 19:36:59 25 4
gpt4 key购买 nike

我真的很想利用本地安装的 firebase-server 编写一些集成测试,这将模仿实时数据库服务器。

我有installed它并从 CLI 启动它:node_modules/.bin/firebase-server -p 5000

但我无法通过 Swift 连接到它。按照 Firebase 的文档,需要在项目中下载使用 GoogleService-Info.plist。这显然必须改变,因为我想改为连接到本地服务器。

这就是我现在在 AppDelegate.swift 中的内容:

var firebaseConfig: String!
if isRunningTests() {
// unit test server (idealy local)
firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info-tests", ofType: "plist")
} else {
#if DEBUG
// staging server
firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist")
#else
// production server
firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info-prod", ofType: "plist")
#endif
}

guard let options = FIROptions(contentsOfFile: firebaseConfig) else {
fatalError("Invalid Firebase configuration file.")
}

FIRApp.configure(with: options)
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
FIRDatabase.database().persistenceEnabled = true

这意味着对于单元测试,我加载 GoogleService-Info-tests plist 并连接到远程测试数据库。我怎样才能连接到 ws://test.firebase.localhost:5000 ?我不清楚 options 中的哪些变量是必需的并且需要提供。

最佳答案

您可以使用 FIROptions init!(googleAppID: String!, bundleID: String!, gcmSenderID GCMSenderID: String!, apiKey APIKey: String!, clientID: String!, trackingID: String!, androidClientID: String! , databaseURL: String!, storageBucket: String!, deepLinkURLScheme: String!) 方法并传入AppId、bundleId、来自真实应用的SenderID,然后传入databaseURL,可以是本地URL。您应该能够将 nil 传递给其他人并且没问题(尽管您可能必须关闭编译器警告,因为它们在 Swift 中似乎被标记为不可为空)。

或者您可以更改 GoogleService-Info-tests.plist 中的一个字段以指向新数据库。

关于ios - 如何通过 Swift 连接到本地 Firebase 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43564715/

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