FirebaseAppUtils.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2025 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. import FirebaseCore
  15. extension FirebaseApp {
  16. /// Configures a Firebase app with the specified name and Google Service Info plist file name.
  17. ///
  18. /// - Parameters:
  19. /// - appName: The Firebase app's name; see ``FirebaseAppNames`` for app names with special
  20. /// meanings in the TestApp.
  21. /// - plistName: The file name of the Google Service Info plist, excluding the file extension;
  22. /// for the default app this is typically called `GoogleService-Info` but any file name may be
  23. /// used for other apps.
  24. static func configure(appName: String, plistName: String) {
  25. assert(!plistName.hasSuffix(".plist"), "The .plist file extension must be omitted.")
  26. guard let plistPath =
  27. Bundle.main.path(forResource: plistName, ofType: "plist") else {
  28. fatalError("The file '\(plistName).plist' was not found.")
  29. }
  30. guard let options = FirebaseOptions(contentsOfFile: plistPath) else {
  31. fatalError("Failed to parse options from '\(plistName).plist'.")
  32. }
  33. FirebaseApp.configure(name: appName, options: options)
  34. }
  35. }