How to connect to a local Firebase server through Swift?

I really would like to write some integration tests using a local firebase-server installation that will simulate a real-time database server.

I installed it and started with the CLI: node_modules/.bin/firebase-server -p 5000

But I have problems connecting to it through Swift. Following the documents for Firebase, you need to download the utility GoogleService-Info.plistin the project. This obviously needs to change as I want to connect to the local server.

This is what I have right now in 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

, plist GoogleService-Info-tests . ws://test.firebase.localhost:5000? , options .

+4
1

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, .

+1

Source: https://habr.com/ru/post/1675418/


All Articles