How to display permission to track in iOS 14.5 and above in Swift?

import AppTrackingTransparency
  1. You must add an if statement to check if the iOS version is 14 and above.
  2. Use the method requestTrackingAuthorization(completionHandler:) to display permission to track.
    Note: This is permission will only be displayed once to the user during the first time the user has opened the application.
if #available(iOS 14, *) {
// Display permission to track
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
switch status {
case .notDetermined:
print("Unknown consent")
case .restricted:
print("Device has an MDM solution applied")
case .denied:
print("Denied consent")
case .authorized:
print("Granted consent")
default:
print("Unknown")
}
})
}
  1. The case .authorized meant the user has authorized the application.
  2. The case .restricted meant the display permission not shown to the user and also tracking restricted.
  3. The case .denied meant the user has not authorized the application.
  4. The case .notDetermined meant the application cannot determine the authorisation status for access.

--

--

--

Software Engineer (Android, iOS, Unity) | M.Sc. Computer Science — Technische Universitaet Berlin | Mobile Advertising, Attribution, Monetisation, UA & Analytic

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Image crop some part of both image and swap it

iOS: Create Stretchable Scroll view like in Spotify playlist with Swift

Here are 3 things you need to know before you install the iOS 15 beta

Phantom Types in Swift

Working with JSON in Swift

Goal Tracking App

An Introduction to SwiftUI

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akarsh SEGGEMU

Akarsh SEGGEMU

Software Engineer (Android, iOS, Unity) | M.Sc. Computer Science — Technische Universitaet Berlin | Mobile Advertising, Attribution, Monetisation, UA & Analytic

More from Medium

iOS: Integrate Firebase Crashlytics properly

Using Singletons in Swift and UIKit

My Swift Journey With 100 Days of SwiftUI

How to change a List’s background color in SwiftUI