79497764

Date: 2025-03-10 10:58:41
Score: 0.5
Natty:
Report link

How to Add the AppTrackingTransparency (ATT) Permission to Your iOS App?

Starting from iOS 14, Apple requires apps to request user permission before accessing the Identifier for Advertisers (IDFA) for tracking. This is done using AppTrackingTransparency (ATT). Below are the steps to implement ATT permission in your iOS app.

1️⃣ Add Usage Description in Info.plist

Before requesting permission, you must add a privacy description in your Info.plist file.

📌 Open Info.plist and add the following key-value pair:

<key>NSUserTrackingUsageDescription</key>
<string>We use tracking to provide personalized content and improve your experience.</string>

This message will be displayed in the ATT system prompt.

2️⃣ Request Tracking Permission in Swift

To request tracking permission, use the AppTrackingTransparency framework.

📌 Update AppDelegate.swift or call this in your ViewController:

import UIKit
import AppTrackingTransparency

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        requestTrackingPermission()
        return true
    }

    /// Requests App Tracking Transparency (ATT) permission
    func requestTrackingPermission() {
        if #available(iOS 14, *) {
            ATTrackingManager.requestTrackingAuthorization { status in
                switch status {
                case .authorized:
                    print("✅ Tracking Authorized")
                case .denied:
                    print("❌ Tracking Denied")
                case .restricted:
                    print("🔒 Tracking Restricted (e.g., parental controls)")
                case .notDetermined:
                    print("⏳ Tracking Not Determined")
                @unknown default:
                    print("❓ Unknown Tracking Status")
                }
            }
        } else {
            print("⚠️ ATT Not Supported (iOS version < 14)")
        }
    }
}

3️⃣ Run on a Real iOS Device (Not Simulator)

🚨 ATT does NOT work on the iOS Simulator.
You must test on a real iPhone running iOS 14 or later.

Run the app on a real device using:

xcodebuild -scheme YourApp -destination 'platform=iOS,name=Your Device Name' run

4️⃣ Verify ATT in iPhone Settings

Once you request tracking permission:

  1. Open Settings → Privacy & Security → Tracking.

  2. Check if your app appears in the list.

  3. If your app appears with a toggle, ATT is working correctly! ✅

5️⃣ Debug ATT in Xcode (Check Logs)

To ensure that ATT is working properly, open Xcode Console (Cmd + Shift + C) and check the logs:

✅ Tracking Authorized
❌ Tracking Denied
🔒 Tracking Restricted (e.g., parental controls)
⏳ Tracking Not Determined

6️⃣ Reset Tracking Permissions (If No Prompt Appears)

If the ATT popup does not appear, reset tracking permissions:

  1. Open Settings → Privacy & Security → Tracking.

  2. Toggle "Allow Apps to Request to Track" OFF and ON.

  3. Delete and reinstall the app.

  4. Restart your iPhone.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How to Add the
  • Low reputation (1):
Posted by: Mirza