How to connect via Swift?
Closed this issue · 3 comments
Is there any chance to explain how to connect to this via Swift on iOS? The way Firebase currently works is that it requires a Google-Service-Info.plist, which predefines all the necessary fields to connect to the remote server. I’m unsure about how to provide that for the local database.
Any help would be highly appreciated,
Houman
In other words how to I connect in AppDelegate.swift via FIRApp.configure(with: options)
to the local firebase-server?
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
I've added more info here:
https://stackoverflow.com/questions/43564715/how-to-connect-to-local-firebase-server-via-swift
You can use the FIROptions init!(googleAppID: String!, bundleID: String!, gcmSenderID GCMSenderID: String!, apiKey APIKey: String!, clientID: String!, trackingID: String!, androidClientID: String!, databaseURL: String!, storageBucket: String!, deepLinkURLScheme: String!)
method and pass in AppId, bundleId, SenderID from a real app, and then databaseURL, which can be a local URL. You should be able to pass nil
into the others and be fine (though you may have to silence compiler warnings since they appear to be marked as non-nullable in Swift).
Or you can change the one field in your GoogleService-Info-tests.plist
to point to the new Database.
Thanks that works.