The App Tracking Transparency framework is used to present a permission request alert.
The permission totally depends on the user whether the user wants to allow or deny it.
If the user denies permission the app cannot collect the user’s data. And if it allows it then the app can collect the data.
This framework presents the app tracking authorization request to the user.
ATT is the short form of App Tracking Transparency
ATT manager provides the functionality of authorization request and handling.
What is NSUserTrackingUsageDescription
The UsageDescription is used to explain the reason why your data is needed is called Usages Description.
Tracking Authorization Status
App Tracking Transparency status completely handled by the user.
Use this property to check the authorization request.
Tracking Authorization Request
The alert that asks for permission to access data is known as an Authorization request alert.
Let’s start code
Info.plist
1 2 |
<key>NSUserTrackingUsageDescription</key> <string>This identifier will be used to deliver personalized ads to you.</string> |
Use the above key and value in info.plist file to access permission.
ViewController
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import UIKit import AppTrackingTransparency import AdSupport class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() DispatchQueue.main.asyncAfter(deadline: .now() + 1){ self.requestPermission() } // Do any additional setup after loading the view. } func requestPermission() { if #available(iOS 14, *) { ATTrackingManager.requestTrackingAuthorization { 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") } } } else { // Fallback on earlier versions } } } |
Let’s see the output images
Conclusion:-
In this blog, we discussed the working of AppTrackingTransparency in-app.
I hope this blog will help you to understand the functionality.
Thanks for reading!!!