AppDelegate.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. import FirebaseAnalytics
  17. @UIApplicationMain
  18. class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
  19. func application(_ application: UIApplication,
  20. didFinishLaunchingWithOptions launchOptions: [UIApplication
  21. .LaunchOptionsKey: Any]?) -> Bool {
  22. FirebaseApp.configure()
  23. FirebaseAnalytics.Analytics.logEvent("test", parameters: nil)
  24. let center = UNUserNotificationCenter.current()
  25. center.delegate = self
  26. center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
  27. if error != nil {
  28. print("Failed requesting notification permission: ", error ?? "")
  29. }
  30. }
  31. application.registerForRemoteNotifications()
  32. return true
  33. }
  34. // Implement this to display notification when app is in foreground.
  35. func userNotificationCenter(_ center: UNUserNotificationCenter,
  36. willPresent notification: UNNotification,
  37. withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions)
  38. -> Void) {
  39. completionHandler([.alert, .sound])
  40. }
  41. func userNotificationCenter(_ center: UNUserNotificationCenter,
  42. didReceive response: UNNotificationResponse,
  43. withCompletionHandler completionHandler: @escaping () -> Void) {
  44. completionHandler()
  45. }
  46. }