I am trying to implement App Tracking Transparency in my app. I tried to do this on first ViewControllor, but it crashes the app after uploading to the test flight.
After this, I found a lot of info that this should be done in appDelegate I did this way. Of course, I have set NSUserTrackingUsageDescription in Info.plist
I tried to figure it out with this post.
In the debugger, I always see "Not Determined". Could anyone please help with this?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
requestTrackingPermission()
GADMobileAds.sharedInstance().start(completionHandler: nil)
return true
}
The function
func requestTrackingPermission() {
if #available(iOS 14, *) {
// ATTrackingManager.requestTrackingAuthorization { status in
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
switch status {
case .authorized:
// Tracking authorization dialog was shown
// and we are authorized
print("Authorized")
// Now that we are authorized we can get the IDFA
print(ASIdentifierManager.shared().advertisingIdentifier)
case .denied:
// Tracking authorization dialog was
// shown and permission is denied
print("Denied")
case .notDetermined:
// Tracking authorization dialog has not been shown
print("Not Determined")
case .restricted:
print("Restricted")
@unknown default:
print("Unknown")
}
}
)}
}