Last updated: October 21st, 2019.
At the time of writing this gist (January 4th, 2017), I was unable to find true sandboxing to separate development and production environments for a Firebase project. The closest we can get is to create two separate Firebase projects -- one for development and one for production.
- Complete separation and isolation of all Firebase features.
- Freedom to experiment without risking the corruption of production data.
- There is no way to copy production data to your development project (that I am aware of).
- Any settings changes made to your development project also needs to be manually applied to your production project.
This method will not work correctly with Crashlyitcs. Crashlytics has "GoogleService-Info.plist" hardcoded somewhere, so renaming the file will not work. Instead, consider setting up multiple directories, one for each Firebase project, and use a build script to move the Firebase configuration file appropriately. See this comment for more details.
-
Go to the Firebase console.
-
Create two projects. That's Projects, not Apps. Apps within a project share certain features, including the Realtime Database. Make sure both projects have a Bundle ID matching your Xcode project's Bundle ID.
-
In each project, create an iOS App, and each
GoogleServices-Info.plistfile to your Xcode project. -
Rename one of the
plistfiles to clearly identify it as the development (or production) configuration, such asGoogleServices-Info-Dev.plist. -
Configure Firebase with the following code:
Swift
#if DEBUG let firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info-Dev", ofType: "plist") #else let firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") #endif guard let options = FIROptions(contentsOfFile: firebaseConfig) else { fatalError("Invalid Firebase configuration file.") } FIRApp.configure(with: options)
Objective-C
#if DEBUG NSString *firebaseConfig = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info-Dev" ofType:@"plist"]; #else NSString *firebaseConfig = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]; #endif FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:firebaseConfig]; if (options == nil) { // Invalid Firebase configuration file. return; } [FIRApp configureWithOptions:options];
Now, when your app is run from Xcode, your development Firebase project will be used.
Note that if you are using
FirebaseAuth, you will need to setup each authentication method (i.e. Google, Facebook) for both Firebase projects.
- TheiOSChap on StackOverflow
- or-else for Crashlytics build script
If you know of a better method, please let me know. This isn't ideal, but I think it works well for what we're given.
Sorry guys, GitHub really needs to implement Gist notifications.
@balrajOla The Firebase documentation recommends configuring Firebase in the
application:didFinishLaunchingWithOptions, but there is nothing that says it can't be configured again during runtime. If this is possible, the process would be the same. Instead of using the#if DEBUGdirective, you would use your runtime equivalent variable to determine which service file to use, and then callFIRApp.configureagain.Source: https://firebase.google.com/docs/ios/setup
@AstmDesign I don't know Android as well, but a quick search shows that it can be done using Gradle configuration:
https://stackoverflow.com/questions/30772201/google-services-json-for-different-productflavors