App Tracking Transparency in iOS 15 (Swift & SwiftUI)

Federica Benacquista
3 min readFeb 13, 2022

I recently tried to publish an app where I implemented the ATT popup in a common view controller.

No need to say that Apple rejected it because it wouldn’t show up on iOS 15 and above (it worked fine on iOS 14).

So after a while of searching and trying, I found the solution:

The fist 2 steps have to be done both for Swift and SwiftUI.

  1. Import the AppTrackingTransparency framework to your target.

2. In your Info.plist file, you need to add the tracking usage description key which, in code is the following:

<key>NSUserTrackingUsageDescription</key><string>This identifier will be used to deliver personalized ads to you</string>

3. Present the pop-up.

Swift

Before I show you how to do it remember the following information:

  • You must only show the pop-up once. This means the code to show it must be called once.
  • If you can’t see the popup on your device, check your settings to see if tracking is enabled.
  • It can take some time for the pop-up to show after you implement my code (normally it would be a few seconds, be patient).
  • The pop up has to be presented when the app status becomes active (UIApplicationStateActive). This means there are two places where we can show the pop-up: if we were using the AppDelegate then we’d go for the applicationDidBecomeActive method. However, if we were using the SceneDelegate, we’d need to present it through the sceneDidBecomeActive method. Now you may think “well what if my app has both AppDelegate and SceneDelegate?” well, I don’t really know why but just put the code in the SceneDelegate and it will work (I promise I will update this article if I discover the reason).

Now let’s dive in!

I am using the SceneDelegate.

First thing first, import the framework:

#import AppTrackingTransparency

Then present the pop-up:

func sceneDidBecomeActive(_ scene: UIScene) {DispatchQueue.main.asyncAfter(deadline…
Federica Benacquista

I’m a self taught iOS developer and soon to be entrepreneur. I like to explain tricky concepts as easily as possible and it’s exactly what I do here.