Skip to content

Commit 8b1fc94

Browse files
alanjcharlesAlan Charles
andauthored
fix: fix timing issue in idfa (#125)
* fix: fix timing issue in idfa * refactor: flip alreadyAsked var and askForPermission() * refactor: remove space Co-authored-by: Alan Charles <[email protected]>
1 parent 4e1ac89 commit 8b1fc94

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Examples/other_plugins/IDFACollection.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ import AppTrackingTransparency
4747
class IDFACollection: Plugin {
4848
let type = PluginType.enrichment
4949
var analytics: Analytics? = nil
50+
@Atomic private var alreadyAsked = false
5051

5152
func execute<T: RawEvent>(event: T?) -> T? {
5253
let status = ATTrackingManager.trackingAuthorizationStatus
53-
if status == .notDetermined {
54-
// we don't know, so should ask the user.
55-
askForPermission()
56-
}
57-
54+
5855
let trackingStatus = statusToString(status)
5956
var idfa = fallbackValue
6057
var adTrackingEnabled = false
@@ -77,6 +74,17 @@ class IDFACollection: Plugin {
7774
}
7875
}
7976

77+
extension IDFACollection: iOSLifecycle {
78+
func applicationDidBecomeActive(application: UIApplication?) {
79+
let status = ATTrackingManager.trackingAuthorizationStatus
80+
if status == .notDetermined && !alreadyAsked {
81+
// we don't know, so should ask the user.
82+
alreadyAsked = true
83+
askForPermission()
84+
}
85+
}
86+
}
87+
8088
extension IDFACollection {
8189
var fallbackValue: String? {
8290
get {

0 commit comments

Comments
 (0)