AppDelegate.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2020 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 UIKit
  15. import FirebaseCore
  16. @UIApplicationMain
  17. class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
  18. func application(_ application: UIApplication,
  19. didFinishLaunchingWithOptions launchOptions: [UIApplication
  20. .LaunchOptionsKey: Any]?) -> Bool {
  21. FirebaseApp.configure()
  22. let center = UNUserNotificationCenter.current()
  23. center.delegate = self
  24. center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
  25. if error != nil {
  26. print("Failed requesting notification permission: ", error ?? "")
  27. }
  28. }
  29. application.registerForRemoteNotifications()
  30. return true
  31. }
  32. // Implement this to display notification when app is in foreground.
  33. func userNotificationCenter(_ center: UNUserNotificationCenter,
  34. willPresent notification: UNNotification,
  35. withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions)
  36. -> Void) {
  37. completionHandler([.alert, .sound])
  38. }
  39. // MARK: UISceneSession Lifecycle
  40. func application(_ application: UIApplication,
  41. configurationForConnecting connectingSceneSession: UISceneSession,
  42. options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  43. // Called when a new scene session is being created.
  44. // Use this method to select a configuration to create the new scene with.
  45. return UISceneConfiguration(name: "Default Configuration",
  46. sessionRole: connectingSceneSession.role)
  47. }
  48. }