0

I'm running on simulator with iOS15, and my app is iOS14+. The status in completion block always returns .notDetermined

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {    
    ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
        print(status) // .notDetermined
    })
}

Things I have already done:

  • Add NSUserTrackingUsageDescription to info.plist
  • Enable Settings > Privacy > Tracking > Allow Apps to Request to Track

The question is NOT a duplicate of this question because I'm running it normally in Simulator and not UI test.

matchifang
  • 5,190
  • 12
  • 47
  • 76
  • You are calling your request at a wrong place under iOS 15. – El Tomato Oct 23 '21 at 00:25
  • Does this answer your question? [App Tracking Transparency Dialog does not appear on iOS](https://stackoverflow.com/questions/69418845/app-tracking-transparency-dialog-does-not-appear-on-ios) – El Tomato Oct 23 '21 at 00:25

1 Answers1

1

It is essentially duplicate to the question you linked to in that root cause is the same.

The problem is you are asking the system to display the consent dialog before there is a view controller that the dialog can be presented from.

The earliest you can display the tracking consent dialog is in viewDidAppear of your first view controller, since at that point you know that there is a view controller visible on screen.

The answer in the question you linked to avoids the problem by dispatching the tracking request after a short delay which gives enough time for the initial view controller to be presented.

I am not a big fan of this sort of fix, but you can use it if you like.

A better solution is to move your tracking consent into an appropriate object and invoke a method on that object in your first view controller.

Paulw11
  • 108,386
  • 14
  • 159
  • 186