1
- import Foundation
2
1
import Dependencies
2
+ import Foundation
3
3
import UserNotifications
4
4
5
5
extension UserNotificationClient : DependencyKey {
@@ -9,44 +9,44 @@ extension UserNotificationClient: DependencyKey {
9
9
var client = UserNotificationClient ( )
10
10
client. add = { try await UNUserNotificationCenter . current ( ) . add ( $0) }
11
11
12
- #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
13
- client. deliveredNotifications = {
14
- let notifications = await center. deliveredNotifications ( )
15
- return notifications. map ( Notification . init ( rawValue: ) )
16
- }
17
- #endif
12
+ #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
13
+ client. deliveredNotifications = {
14
+ let notifications = await center. deliveredNotifications ( )
15
+ return notifications. map ( Notification . init ( rawValue: ) )
16
+ }
17
+ #endif
18
18
19
19
client. notificationSettings = {
20
20
let settings = await center. notificationSettings ( )
21
21
return Notification . Settings ( rawValue: settings)
22
22
}
23
23
24
- #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
25
- client. notificationCategories = {
26
- await center. notificationCategories ( )
27
- }
28
- #endif
24
+ #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
25
+ client. notificationCategories = {
26
+ await center. notificationCategories ( )
27
+ }
28
+ #endif
29
29
30
30
client. pendingNotificationRequests = {
31
31
let requests = await center. pendingNotificationRequests ( )
32
32
return requests. map ( Notification . Request. init ( rawValue: ) )
33
33
}
34
34
35
- #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
36
- client. removeAllDeliveredNotifications = {
37
- center. removeAllDeliveredNotifications ( )
38
- }
39
- #endif
35
+ #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
36
+ client. removeAllDeliveredNotifications = {
37
+ center. removeAllDeliveredNotifications ( )
38
+ }
39
+ #endif
40
40
41
41
client. removeAllPendingNotificationRequests = {
42
42
center. removeAllPendingNotificationRequests ( )
43
43
}
44
44
45
- #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
46
- client. removeDeliveredNotificationsWithIdentifiers = {
47
- center. removeDeliveredNotifications ( withIdentifiers: $0)
48
- }
49
- #endif
45
+ #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
46
+ client. removeDeliveredNotificationsWithIdentifiers = {
47
+ center. removeDeliveredNotifications ( withIdentifiers: $0)
48
+ }
49
+ #endif
50
50
51
51
client. removePendingNotificationRequestsWithIdentifiers = {
52
52
center. removePendingNotificationRequests ( withIdentifiers: $0)
@@ -56,11 +56,11 @@ extension UserNotificationClient: DependencyKey {
56
56
try await center. requestAuthorization ( options: $0)
57
57
}
58
58
59
- #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
60
- client. setNotificationCategories = {
61
- center. setNotificationCategories ( $0)
62
- }
63
- #endif
59
+ #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
60
+ client. setNotificationCategories = {
61
+ center. setNotificationCategories ( $0)
62
+ }
63
+ #endif
64
64
65
65
client. supportsContentExtensions = {
66
66
center. supportsContentExtensions
@@ -80,8 +80,8 @@ extension UserNotificationClient: DependencyKey {
80
80
}
81
81
}
82
82
83
- private extension UserNotificationClient {
84
- class Delegate : NSObject , UNUserNotificationCenterDelegate {
83
+ extension UserNotificationClient {
84
+ fileprivate class Delegate : NSObject , UNUserNotificationCenterDelegate {
85
85
let continuation : AsyncStream < UserNotificationClient . DelegateAction > . Continuation
86
86
87
87
init ( continuation: AsyncStream < UserNotificationClient . DelegateAction > . Continuation ) {
@@ -92,7 +92,7 @@ private extension UserNotificationClient {
92
92
_ center: UNUserNotificationCenter ,
93
93
willPresent notification: UNNotification ,
94
94
withCompletionHandler completionHandler:
95
- @escaping ( UNNotificationPresentationOptions ) -> Void
95
+ @escaping ( UNNotificationPresentationOptions ) -> Void
96
96
) {
97
97
self . continuation. yield (
98
98
. willPresentNotification(
@@ -102,29 +102,29 @@ private extension UserNotificationClient {
102
102
)
103
103
}
104
104
105
- #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
106
- func userNotificationCenter(
107
- _ center: UNUserNotificationCenter ,
108
- didReceive response: UNNotificationResponse ,
109
- withCompletionHandler completionHandler: @escaping ( ) -> Void
110
- ) {
111
- let wrappedResponse = Notification . Response ( rawValue: response)
112
- self . continuation. yield (
113
- . didReceiveResponse( wrappedResponse) { completionHandler ( ) }
114
- )
115
- }
116
- #endif
117
-
118
- #if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
119
- func userNotificationCenter(
120
- _ center: UNUserNotificationCenter ,
121
- openSettingsFor notification: UNNotification ?
122
- ) {
123
- let mappedNotification = notification. map ( Notification . init)
124
- self . continuation. yield (
125
- . openSettingsForNotification( mappedNotification)
126
- )
127
- }
128
- #endif
105
+ #if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
106
+ func userNotificationCenter(
107
+ _ center: UNUserNotificationCenter ,
108
+ didReceive response: UNNotificationResponse ,
109
+ withCompletionHandler completionHandler: @escaping ( ) -> Void
110
+ ) {
111
+ let wrappedResponse = Notification . Response ( rawValue: response)
112
+ self . continuation. yield (
113
+ . didReceiveResponse( wrappedResponse) { completionHandler ( ) }
114
+ )
115
+ }
116
+ #endif
117
+
118
+ #if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
119
+ func userNotificationCenter(
120
+ _ center: UNUserNotificationCenter ,
121
+ openSettingsFor notification: UNNotification ?
122
+ ) {
123
+ let mappedNotification = notification. map ( Notification . init)
124
+ self . continuation. yield (
125
+ . openSettingsForNotification( mappedNotification)
126
+ )
127
+ }
128
+ #endif
129
129
}
130
130
}
0 commit comments