App Tracking Transparency Framework in Swift and iOS 14.5
Apple has begun rejecting app submissions that do not follow its updated privacy policies regarding device fingerprinting and user tracking after iOS 14.5 release.
You must use the AppTrackingTransparency framework if your app collects data about end users and shares it with other companies (3rd party framework) for purposes of tracking across apps and web sites.
Note :- AppTrackingTransparency framework only available from Xcode 12 and iOS 14.
Follow the Steps
- Set up a
NSUserTrackingUsageDescription
to display a system-permission alert request for your app installed on end-user devices.
- Select your project’s
Info.plist
file in Xcode Project navigator. - Add key Privacy — Tracking Usage Description. Keep the description text short and specific. You don’t need to include your app name because the system already identifies your app.
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
2. Call requestTrackingAuthorization(completionHandler:)
to present the app-tracking authorization request to the end user.
One-time request to authorize or deny access to app-related data. It doesn’t prompt again unless the user uninstalls and then reinstalls the app on the device.
Import the AppTrackingTransparency
and then request for the authentication popup as shown below.
import AppTrackingTransparencyfunc 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")
}
}
}
}
3. Check the authentication permission status using trackingAuthorizationStatus
Authentication Status :-
- authorized
- denied
- notDetermined
- restricted
Thanks for reading. If you enjoy this article make sure to clap to show your support and share with others.