I have read all exisiting posts about this topic, but until now I can not get it to work. Somehow calling ATTrackingManager.requestTrackingAuthorization never shows the popup. I added Privacy - Tracking Usage Description to the info list. I also turned on the system permissions.
I am developing the app with SwiftUI. Target device runs ios 15.4. Any ideas what else to try? Maybe this is related to swiftUI?
Code:
DeckListView(decks: $store.decks){
Task {
....
}
}
}.onAppear{
requestPermission()
}
func requestPermission() {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
print("Authorized")
print(ASIdentifierManager.shared().advertisingIdentifier)
case .denied:
print("Denied")
case .notDetermined:
// Tracking authorization dialog has not been shown
// always the case for me
print("Not Determined")
case .restricted:
print("Restricted")
@unknown default:
print("Unknown")
}
}
}
}
}
Finally I found the source of my problem.
I accidentally called ATTrackingManager.requestTrackingAuthorization
twice.
The first time I called while the app was not in an active state. It seems if the first call is made outside active state, any other calls will no longer show the popup.