AppDelegate.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2021 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 FirebaseAuth
  15. import FirebaseCore
  16. import FBSDKCoreKit
  17. import UIKit
  18. @objc protocol OpenURLDelegate: AnyObject {
  19. func handleOpenURL(_ url: URL, sourceApplication: String) -> Bool
  20. }
  21. @main
  22. public class AppDelegate: UIResponder, UIApplicationDelegate {
  23. weak static var gOpenURLDelegate: OpenURLDelegate?
  24. public var window: UIWindow?
  25. var sampleAppMainViewController: MainViewController?
  26. @objc class func setOpenURLDelegate(_ openURLDelegate: OpenURLDelegate?) {
  27. gOpenURLDelegate = openURLDelegate
  28. }
  29. public func application(_ application: UIApplication,
  30. didFinishLaunchingWithOptions launchOptions: [UIApplication
  31. .LaunchOptionsKey: Any]?) -> Bool {
  32. GTMSessionFetcher.setLoggingEnabled(true)
  33. FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.info)
  34. // Configure the default Firebase application.
  35. FirebaseApp.configure()
  36. // Configure Facebook Login.
  37. ApplicationDelegate.shared.application(
  38. application,
  39. didFinishLaunchingWithOptions: launchOptions
  40. )
  41. // Load and present the UI.
  42. let window = UIWindow(frame: UIScreen.main.bounds)
  43. sampleAppMainViewController = MainViewController(
  44. nibName: NSStringFromClass(MainViewController.self),
  45. bundle: nil
  46. )
  47. sampleAppMainViewController?.navigationItem.title = "Firebase Auth"
  48. window
  49. .rootViewController = UINavigationController(rootViewController: sampleAppMainViewController!)
  50. self.window = window
  51. self.window?.makeKeyAndVisible()
  52. return true
  53. }
  54. public func application(_ app: UIApplication,
  55. open url: URL,
  56. options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
  57. ApplicationDelegate.shared.application(
  58. app,
  59. open: url,
  60. sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
  61. annotation: options[UIApplication.OpenURLOptionsKey.annotation]
  62. )
  63. if Self.gOpenURLDelegate!.handleOpenURL(
  64. url,
  65. sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String
  66. ) {
  67. return true
  68. }
  69. if sampleAppMainViewController!.handleIncomingLink(with: url) {
  70. return true
  71. }
  72. return false
  73. }
  74. public func application(_ application: UIApplication,
  75. continue userActivity: NSUserActivity,
  76. restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void)
  77. -> Bool {
  78. if userActivity.webpageURL != nil {
  79. return sampleAppMainViewController!.handleIncomingLink(with: userActivity.webpageURL!)
  80. }
  81. return false
  82. }
  83. }