-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotificationsPermissionsClient.swift
65 lines (51 loc) · 2.06 KB
/
NotificationsPermissionsClient.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
public struct NotificationsPermissionsClient {
public init(
requestAuthorizationStatus: Operations.RequestAuthorizationStatus,
requestAuthorization: Operations.RequestAuthorization,
configureRemoteNotifications: Operations.ConfigureRemoteNotifications
) {
self.requestAuthorizationStatus = requestAuthorizationStatus
self.requestAuthorization = requestAuthorization
self.configureRemoteNotifications = configureRemoteNotifications
}
public var requestAuthorizationStatus: Operations.RequestAuthorizationStatus
public var requestAuthorization: Operations.RequestAuthorization
public var configureRemoteNotifications: Operations.ConfigureRemoteNotifications
}
extension NotificationsPermissionsClient {
public struct AuthorizationOptions: OptionSet, Equatable {
public var rawValue: UInt
public init(rawValue: UInt) {
self.rawValue = rawValue
}
public static var badge: AuthorizationOptions { .init(rawValue: 1 << 0) }
public static var sound: AuthorizationOptions { .init(rawValue: 1 << 1) }
public static var alert: AuthorizationOptions { .init(rawValue: 1 << 2) }
public static var carPlay: AuthorizationOptions { .init(rawValue: 1 << 3) }
public static var criticalAlert: AuthorizationOptions { .init(rawValue: 1 << 4) }
public static var providesAppNotificationSettings: AuthorizationOptions { .init(rawValue: 1 << 5) }
public static var provisional: AuthorizationOptions { .init(rawValue: 1 << 6) }
#if os(iOS)
public static var announcement: AuthorizationOptions { .init(rawValue: 1 << 7) }
#endif
}
public enum AuthorizationStatus: Equatable {
case notDetermined
case denied
case authorized
case provisional
#if os(iOS)
@available(iOS 14.0, *)
case ephemeral
#endif
case unknown
public var isPermissive: Bool {
#if os(iOS)
if #available(iOS 14.0, *) {
if self == .ephemeral { return true }
}
#endif
return self == .authorized || self == .provisional
}
}
}