-
Notifications
You must be signed in to change notification settings - Fork 1
/
IDFAPermissionsClientLive.swift
65 lines (60 loc) · 1.86 KB
/
IDFAPermissionsClientLive.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
import Combine
import IDFAPermissionsClient
#if !os(watchOS)
import AdSupport
import AppTrackingTransparency
extension IDFAPermissionsClient {
public static let live = IDFAPermissionsClient(
requestAuthorizationStatus: .live,
requestAuthorization: .live,
requestIDFA: .live
)
}
extension IDFAPermissionsClient.Operations.RequestAuthorizationStatus {
public static var live: IDFAPermissionsClient.Operations.RequestAuthorizationStatus {
return .init {
Future { promise in
if #available(iOS 14.0, macOS 11, tvOS 14, *) {
promise(.success(.init(ATTrackingManager.trackingAuthorizationStatus)))
} else {
promise(
.success(
ASIdentifierManager.shared().isAdvertisingTrackingEnabled
? .unavailableWithTrackingEnabled
: .unavailableWithTrackingDisabled
)
)
}
}.eraseToAnyPublisher()
}
}
}
extension IDFAPermissionsClient.Operations.RequestAuthorization {
public static var live: IDFAPermissionsClient.Operations.RequestAuthorization {
return.init { params in
Future { promise in
if #available(iOS 14.0, macOS 11, tvOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
promise(.success(.init(status)))
}
} else {
promise(
.success(
ASIdentifierManager.shared().isAdvertisingTrackingEnabled
? .unavailableWithTrackingEnabled
: .unavailableWithTrackingDisabled
)
)
}
}.eraseToAnyPublisher()
}
}
}
extension IDFAPermissionsClient.Operations.RequestIDFA {
public static var live: IDFAPermissionsClient.Operations.RequestIDFA {
.init { action in
Just(ASIdentifierManager.shared().advertisingIdentifier).eraseToAnyPublisher()
}
}
}
#endif