NotificationSettings.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // NotificationSettings.swift
  3. // LoopKit
  4. //
  5. // Created by Darin Krauss on 9/17/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import Foundation
  9. import UserNotifications
  10. public struct NotificationSettings: Codable, Equatable {
  11. public enum AuthorizationStatus: String, Codable {
  12. case notDetermined
  13. case denied
  14. case authorized
  15. case provisional
  16. case unknown
  17. public init(_ authorizationStatus: UNAuthorizationStatus) {
  18. switch authorizationStatus {
  19. case .notDetermined:
  20. self = .notDetermined
  21. case .denied:
  22. self = .denied
  23. case .authorized:
  24. self = .authorized
  25. case .provisional:
  26. self = .provisional
  27. case .ephemeral:
  28. self = .unknown
  29. @unknown default:
  30. self = .unknown
  31. }
  32. }
  33. }
  34. public enum NotificationSetting: String, Codable {
  35. case notSupported
  36. case disabled
  37. case enabled
  38. case unknown
  39. public init(_ notificationSetting: UNNotificationSetting) {
  40. switch notificationSetting {
  41. case .notSupported:
  42. self = .notSupported
  43. case .disabled:
  44. self = .disabled
  45. case .enabled:
  46. self = .enabled
  47. @unknown default:
  48. self = .unknown
  49. }
  50. }
  51. }
  52. public enum AlertStyle: String, Codable {
  53. case none
  54. case banner
  55. case alert
  56. case unknown
  57. public init(_ alertStyle: UNAlertStyle) {
  58. switch alertStyle {
  59. case .none:
  60. self = .none
  61. case .banner:
  62. self = .banner
  63. case .alert:
  64. self = .alert
  65. @unknown default:
  66. self = .unknown
  67. }
  68. }
  69. }
  70. public enum ShowPreviewsSetting: String, Codable {
  71. case always
  72. case whenAuthenticated
  73. case never
  74. case unknown
  75. public init(_ showPreviewsSetting: UNShowPreviewsSetting) {
  76. switch showPreviewsSetting {
  77. case .always:
  78. self = .always
  79. case .whenAuthenticated:
  80. self = .whenAuthenticated
  81. case .never:
  82. self = .never
  83. @unknown default:
  84. self = .unknown
  85. }
  86. }
  87. }
  88. public let authorizationStatus: AuthorizationStatus
  89. public let soundSetting: NotificationSetting
  90. public let badgeSetting: NotificationSetting
  91. public let alertSetting: NotificationSetting
  92. public let notificationCenterSetting: NotificationSetting
  93. public let lockScreenSetting: NotificationSetting
  94. public let carPlaySetting: NotificationSetting
  95. public let alertStyle: AlertStyle
  96. public let showPreviewsSetting: ShowPreviewsSetting
  97. public let criticalAlertSetting: NotificationSetting
  98. public let providesAppNotificationSettings: Bool
  99. public let announcementSetting: NotificationSetting
  100. public init(authorizationStatus: AuthorizationStatus,
  101. soundSetting: NotificationSetting,
  102. badgeSetting: NotificationSetting,
  103. alertSetting: NotificationSetting,
  104. notificationCenterSetting: NotificationSetting,
  105. lockScreenSetting: NotificationSetting,
  106. carPlaySetting: NotificationSetting,
  107. alertStyle: AlertStyle,
  108. showPreviewsSetting: ShowPreviewsSetting,
  109. criticalAlertSetting: NotificationSetting,
  110. providesAppNotificationSettings: Bool,
  111. announcementSetting: NotificationSetting) {
  112. self.authorizationStatus = authorizationStatus
  113. self.soundSetting = soundSetting
  114. self.badgeSetting = badgeSetting
  115. self.alertSetting = alertSetting
  116. self.notificationCenterSetting = notificationCenterSetting
  117. self.lockScreenSetting = lockScreenSetting
  118. self.carPlaySetting = carPlaySetting
  119. self.alertStyle = alertStyle
  120. self.showPreviewsSetting = showPreviewsSetting
  121. self.criticalAlertSetting = criticalAlertSetting
  122. self.providesAppNotificationSettings = providesAppNotificationSettings
  123. self.announcementSetting = announcementSetting
  124. }
  125. }