Privacy matters! 🫣

Swift | App Tracking Transparency and IDFA on iOS

Sandeep Kumar
3 min readSep 5, 2021

Apple has taken its user’s privacy concerns as a priority and introduced App Tracking Transparency in June 2020 during WWDC20. This blog will be giving you a walkthrough about how to use that Swift in iOS.

What is App Tracking Transparency?

App Tracking Transparency was introduced in iOS14.5 and is a way to prevent apps from collecting user data without consent. Apple has made it mandatory for App owners to disclose what information they are collecting from a user by on the App Store.

It is a replacement for the previous LTA (Limit Ad Tracking) which had Ad tracking as a device-level setting, but now users will be allowed to decide whether to share data on the App level.

What is IDFA?

IDFA (Identifier for Advertisers) is an alphanumeric UUID that is unique to a device. Below are certain points to keep in mind w.r.t it:

  1. It is a common constant to all the Apps installed on the device.
  2. If you access it without requesting user permission, you shall be given a zeroed-out IDFA.
  3. Users can reset the IDFA by disabling and then re-enabling App tracking.
Standard IDFA
30255BCE-4CDA-4F62–91DC-4758FDFF8512
Zeroed out IDFA
00000000–0000–0000–0000–000000000000

Let’s begin with the implementation

Apple introduced the AppTrackingTransparency framework to allow devs to collect data about users and share it with other companies for purposes of tracking across apps and websites.

The framework presents an app-tracking authorization request to the user and provides the tracking authorization status.

Adding tracking usage description

We shall be modifying the info.plist on your project and add NSUserTrackingUsageDescription, this shall contain the message you want to show the user while asking for tracking permission

Request Tracking authorization

You need to import AppTrackingTransparency, prior to accessing ATTrackingManager to request tracking authorization. You shall be given the AuthorizationStatus in the completion of the request, as shown in the code below.

There are 4 possible status values as of now:

  • .authorized - The user has consented to App tracking
  • .denied - The user has denied authorization to access app-related data
  • .notDetermined - value observed prior to an App requesting for tracking
  • .restricted - A restricted condition means the device does not prompt for tracking authorization.

Check Authorisation status

Given that the user can turn off app tracking at any point, you can use ATTrackingManager to check the current authorization status as shown below.

Getting the IDFA

You need to import AdSupport framework in order to access the advertising identifier.

It is recommended to check if access is available prior to accessing the value as the user may choose to restrict it, and because of this reason it is recommended to not store the identifier but access it in real time as the value can be reset as well.

Common issues faced

  1. Calling requestTrackingAuthorization from an extension fails.
  2. Accessing the identifier without authorization returns back a zeroed-out value.
  3. During development, ensure to delete the app if you want to see the App Tracking popup again.

Thank you for reading, and until again! If you have any doubts, let me know in the comments.

👉 Follow me for more content like this.

LinkedIn | Medium | Leetcode | Topmate | Github

--

--

Sandeep Kumar

Software Engineer, love solving real world problems. Enjoy talking about tech.