forked from pointfreeco/swift-custom-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserNotifications.swift
219 lines (206 loc) · 7.08 KB
/
UserNotifications.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#if canImport(UserNotifications)
import UserNotifications
@available(iOS 10, macOS 10.14, *)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension UNAlertStyle: CustomDumpStringConvertible {
public var customDumpDescription: String {
switch self {
case .alert:
return "UNAlertStyle.alert"
case .banner:
return "UNAlertStyle.banner"
case .none:
return "UNAlertStyle.none"
@unknown default:
return "UNAlertStyle.(@unknown default, rawValue: \(self.rawValue))"
}
}
}
@available(iOS 10, macOS 10.14, tvOS 10, watchOS 3, *)
extension UNAuthorizationOptions: CustomDumpReflectable {
public var customDumpMirror: Mirror {
struct Option: CustomDumpStringConvertible {
var rawValue: UNAuthorizationOptions
var customDumpDescription: String {
switch self.rawValue {
case .alert:
return "UNAuthorizationOptions.alert"
#if os(iOS) || os(watchOS)
case .announcement:
return "UNAuthorizationOptions.announcement"
#endif
case .badge:
return "UNAuthorizationOptions.badge"
case .carPlay:
return "UNAuthorizationOptions.carPlay"
case .criticalAlert:
return "UNAuthorizationOptions.criticalAlert"
case .providesAppNotificationSettings:
return "UNAuthorizationOptions.providesAppNotificationSettings"
case .provisional:
return "UNAuthorizationOptions.provisional"
case .sound:
return "UNAuthorizationOptions.sound"
default:
return "UNAuthorizationOptions(rawValue: \(self.rawValue))"
}
}
}
var options = self
var children: [Option] = []
var allCases: [UNAuthorizationOptions] = [
.alert
]
#if os(iOS) || os(watchOS)
allCases.append(.announcement)
#endif
allCases.append(contentsOf: [
.badge,
.carPlay,
.criticalAlert,
.providesAppNotificationSettings,
.provisional,
.sound,
])
for option in allCases {
if options.contains(option) {
children.append(.init(rawValue: option))
options.subtract(option)
}
}
if !options.isEmpty {
children.append(.init(rawValue: options))
}
return .init(
self,
unlabeledChildren: children,
displayStyle: .set
)
}
}
@available(iOS 10, macOS 10.14, tvOS 10, watchOS 3, *)
extension UNAuthorizationStatus: CustomDumpStringConvertible {
public var customDumpDescription: String {
switch self {
case .authorized:
return "UNAuthorizationStatus.authorized"
case .denied:
return "UNAuthorizationStatus.denied"
case .ephemeral:
return "UNAuthorizationStatus.ephemeral"
case .notDetermined:
return "UNAuthorizationStatus.notDetermined"
case .provisional:
return "UNAuthorizationStatus.provisional"
@unknown default:
return "UNAuthorizationStatus.(@unknown default, rawValue: \(self.rawValue))"
}
}
}
// NB: Xcode 13 does not include macOS 12 SDK
#if compiler(>=5.5) && !os(macOS) && !targetEnvironment(macCatalyst)
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)
extension UNNotificationInterruptionLevel: CustomDumpStringConvertible {
public var customDumpDescription: String {
switch self {
case .active:
return "UNNotificationInterruptionLevel.active"
case .critical:
return "UNNotificationInterruptionLevel.critical"
case .passive:
return "UNNotificationInterruptionLevel.passive"
case .timeSensitive:
return "UNNotificationInterruptionLevel.timeSensitive"
@unknown default:
return "UNNotificationInterruptionLevel.(@unknown default, rawValue: \(self.rawValue))"
}
}
}
#endif
@available(iOS 10, macOS 10.14, tvOS 10, watchOS 3, *)
extension UNNotificationPresentationOptions: CustomDumpReflectable {
public var customDumpMirror: Mirror {
struct Option: CustomDumpStringConvertible {
var rawValue: UNNotificationPresentationOptions
var customDumpDescription: String {
if self.rawValue == .alert {
return "UNNotificationPresentationOptions.alert"
} else if self.rawValue == .badge {
return "UNNotificationPresentationOptions.badge"
} else if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *), self.rawValue == .banner {
return "UNNotificationPresentationOptions.banner"
} else if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *), self.rawValue == .list {
return "UNNotificationPresentationOptions.list"
} else if self.rawValue == .sound {
return "UNNotificationPresentationOptions.sound"
} else {
return "UNNotificationPresentationOptions(rawValue: \(self.rawValue))"
}
}
}
var options = self
var children: [Option] = []
var allCases: [UNNotificationPresentationOptions] = [
.alert,
.badge,
]
appendBannerList(&allCases)
allCases.append(.sound)
for option in allCases {
if options.contains(option) {
children.append(.init(rawValue: option))
options.subtract(option)
}
}
if !options.isEmpty {
children.append(.init(rawValue: options))
}
return .init(
self,
unlabeledChildren: children,
displayStyle: .set
)
}
// NB: Workaround for Xcode 13.2's new, experimental build system.
//
// defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
private func appendBannerList(_ allCases: inout [UNNotificationPresentationOptions]) {
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) {
allCases.append(contentsOf: [.banner, .list])
}
}
}
@available(iOS 10, macOS 10.14, tvOS 10, watchOS 3, *)
extension UNNotificationSetting: CustomDumpStringConvertible {
public var customDumpDescription: String {
switch self {
case .disabled:
return "UNNotificationSetting.disabled"
case .enabled:
return "UNNotificationSetting.enabled"
case .notSupported:
return "UNNotificationSetting.notSupported"
@unknown default:
return "UNNotificationSetting.(@unknown default, rawValue: \(self.rawValue))"
}
}
}
@available(iOS 11, macOS 10.14, *)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension UNShowPreviewsSetting: CustomDumpStringConvertible {
public var customDumpDescription: String {
switch self {
case .always:
return "UNShowPreviewsSetting.always"
case .never:
return "UNShowPreviewsSetting.never"
case .whenAuthenticated:
return "UNShowPreviewsSetting.whenAuthenticated"
@unknown default:
return "UNShowPreviewsSetting.(@unknown default, rawValue: \(self.rawValue))"
}
}
}
#endif