Hi everyone,
As you know, due to a bug in iOS 17.4, ATTrackingManager.requestTrackingAuthorization() immediately triggers the callback with a value of status = denied, even though the true value of ATTrackingManager.trackingAuthorizationStatus is still notDetermined because the user has not yet made a choice by responding to the tracking consent popup. The issue persists on iOS 17.4.1.
Anyway, the app triggers a didBecomeActiveNotification when the user responds to the popup, so we can use this workaround to avoid the issue and proceed only after the user has made a choice:
func requestTrackingAuthorization() {
self.removeObserver()
ATTrackingManager.requestTrackingAuthorization {
[weak self] status in
if status == .denied,
ATTrackingManager.trackingAuthorizationStatus == .notDetermined {
debugPrint("iOS 17.4 authorization bug detected")
self?.addObserver()
return
}
debugPrint("status = \(status)")
}
}
private weak var observer: NSObjectProtocol?
private func addObserver() {
self.removeObserver()
self.observer = NotificationCenter.default.addObserver(
forName: UIApplication.didBecomeActiveNotification,
object: nil,
queue: .main
) { [weak self] _ in
self?.requestTrackingAuthorization()
}
}
private func removeObserver() {
if let observer {
NotificationCenter.default.removeObserver(observer)
}
self.observer = nil
}