Use more than one Firebase database in single app - Swift

后端 未结 2 1418
我在风中等你
我在风中等你 2021-02-08 13:08

I have a firebase database currently connected to my app with the GoogleService-Info.plist, etc. It works great.

I would like to connect my app to a second firebase data

2条回答
  •  有刺的猬
    2021-02-08 14:01

    The proper way to initialize another database is to initialize another app, using the FIROptions constructor, like so:

    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
    

    Or you can initialize from another named plist rather than a huge constructor:

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

提交回复
热议问题