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.plist
file to your Xcode project. -
Rename one of the
plist
files 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.
@jjdp Sorry, I just saw this now, and I imagine you've solved your issue. Regardless, here's what I think the Objective-C equivalent would be (beware, this is untested).
E: Ah, I see you have solved it in your fork. :)