AppManager.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. @testable import FirebaseAuth
  15. import FirebaseCore
  16. import UIKit
  17. /// Manage FirebaseApp instances for the Sample app
  18. class AppManager {
  19. static let shared = AppManager()
  20. private var defaultApp: FirebaseApp
  21. private var otherApp: FirebaseApp
  22. var app: FirebaseApp
  23. func auth() -> Auth {
  24. return Auth.auth(app: app)
  25. }
  26. private init() {
  27. defaultApp = FirebaseApp.app()!
  28. app = FirebaseApp.app()!
  29. guard let path = Bundle.main.path(forResource: "GoogleService-Info_multi", ofType: "plist"),
  30. let options = FirebaseOptions(contentsOfFile: path) else {
  31. fatalError("GoogleService-Info_multi.plist must be added to the project")
  32. }
  33. FirebaseApp.configure(name: "OtherApp", options: options)
  34. guard let other = FirebaseApp.app(name: "OtherApp") else {
  35. fatalError("Failed to find OtherApp")
  36. }
  37. otherApp = other
  38. }
  39. func toggle() {
  40. if app == defaultApp {
  41. app = otherApp
  42. } else {
  43. app = defaultApp
  44. }
  45. }
  46. }