[英]How to read/write from one IOS App set up with firebase, to another firebase database contained in another firebase project? Swift 3
[英]Get Firebase database from another firebase app
如何从swift5中的另一个firebase应用程序访问firebase数据库? 我们在一个帐户中有两个应用程序,一个是司机应用程序和骑手应用程序。 我将数据存储在驾驶员实时数据库中,并希望在骑手应用程序中访问该数据库。 让我知道是否有人有此解决方案。
要从两个 iOS 应用程序访问同一个数据库,您只需在该项目的 Firebase 控制台中创建两个应用程序。 这将为您提供一个包含两个应用程序信息的GoogleService-Info.plist
文件,每个应用程序将根据 iOS 包 ID 从那里选择其配置。
另请参阅 iOS 开发人员的 Firebase 设置说明中注册应用程序的第 2 步。
在此之后,两个应用程序都可以访问同一个数据库以及所有其他服务。
这是在单个 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.