SwiftUISampleApp.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2022 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import SwiftUI
  17. import FirebaseCore
  18. import FirebaseRemoteConfig
  19. import FirebaseRemoteConfigSwift
  20. class AppDelegate: NSObject, UIApplicationDelegate {
  21. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
  22. FirebaseApp.configure()
  23. let config = RemoteConfig.remoteConfig()
  24. let settings = RemoteConfigSettings()
  25. settings.minimumFetchInterval = 0
  26. config.configSettings = settings
  27. try? config.setDefaults(from: ["mobileweek":["section 0": "Breakfast"]])
  28. _ = RemoteConfig.remoteConfig().add(onConfigUpdateListener: { error in
  29. guard error == nil else {
  30. return
  31. }
  32. RemoteConfig.remoteConfig().activate { changed, error in
  33. guard error == nil && changed else {
  34. return
  35. }
  36. }
  37. })
  38. return true
  39. }
  40. }
  41. @main
  42. struct SwiftUISampleApp: App {
  43. @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
  44. var body: some Scene {
  45. WindowGroup {
  46. ContentView(realtimeToggle: false)
  47. }
  48. }
  49. }