【问题标题】:Get Firebase database from another firebase app从另一个 Firebase 应用获取 Firebase 数据库
【发布时间】:2019-11-22 11:17:51
【问题描述】:

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

【问题讨论】:

    标签: ios firebase-realtime-database swift5


    【解决方案1】:

    要从两个 iOS 应用程序访问同一个数据库,您只需在该项目的 Firebase 控制台中创建两个应用程序。这将为您提供一个 GoogleService-Info.plist 文件,其中包含有关这两个应用程序的信息,每个应用程序将根据 iOS 捆绑 ID 从那里选择其配置。

    另请参阅面向 iOS 开发人员的 Firebase 设置说明中register your app 的第 2 步。

    在此之后,两个应用程序可以访问同一个数据库以及所有其他服务。

    【讨论】:

    • 我已经在一个帐户中注册了这两个应用程序。但是当试图在第二个应用程序中获取一个应用程序的数据库时。应用程序崩溃显示错误“无效 URL”。我正在尝试从数据库 url 获取数据。
    【解决方案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)
    

    【讨论】:

    • 所以你的意思是我需要在一个应用程序中添加 2 个 Google-info.plist。对吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多