首页 > 解决方案 > 从另一个 Firebase 应用获取 Firebase 数据库

问题描述

如何从swift5中的另一个firebase应用程序访问firebase数据库?我们在一个帐户中有两个应用程序,一个是司机应用程序和骑手应用程序。我将数据存储在驾驶员实时数据库中,并希望在骑手应用程序中访问该数据库。让我知道是否有人有此解决方案。

标签: iosfirebase-realtime-databaseswift5

解决方案


这是在单个 iOS 应用程序中使用多个 Firebase 数据库的代码

func initDatabase() {

FIRDatabase().database() // gets you the default database
    let options = FIROptions(googleAppID:  bundleID: , GCMSenderID: , APIKey: , clientID: , trackingID: , androidClientID: , databaseURL: "https://othernamespace.firebaseio.com", storageBucket: , deepLinkURLScheme: ) // fill in all the other fields 
    FIRApp.configureWithName("anotherClient", options: options)
    let app = FIRApp(named: "anotherClient")
    FIRDatabase.database(app: app!) // gets you the named other database
 }

或者你可以从另一个命名的 plist 而不是一个巨大的构造函数初始化:

let filePath = NSBundle.mainBundle().pathForResource("Second-GoogleService-Info", ofType:"plist")
let options = FIROptions(contentsOfFile:filePath)

推荐阅读