Skip to content

Instantly share code, notes, and snippets.

@jwhitley
Forked from cohenadair/firebase-sandbox.md
Created January 11, 2017 19:08
Show Gist options
  • Save jwhitley/7b19107618750e19e56ae427b1498717 to your computer and use it in GitHub Desktop.
Save jwhitley/7b19107618750e19e56ae427b1498717 to your computer and use it in GitHub Desktop.
Setting up development and production Firebase environments for iOS

Firebase Environments

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.

Pros

  • Complete separation and isolation of all Firebase features.
  • Freedom to experiment without risking the corruption of production data.

Cons

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

Setup

  1. Go to the Firebase console.
  2. 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.
  3. In each project, create an iOS App, and each GoogleServices-Info.plist file to your Xcode project.
  4. Rename one of the plist files to clearly identify it as the development (or production) configuration, such as GoogleServices-Info-Dev.plist.
  5. Configure Firebase with the following code:
    #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)

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.

Credits

TheiOSChap on StackOverflow

Conclusion

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment