Objective-C: How to display permission to track in iOS 14.5 and above in Objective-C?

Akarsh Seggemu, M.Sc.
2 min readJun 5, 2022

--

Displaying permission to track is a professional way to inform the user of the application that this application will use the app-related data to track the user or device. The user can either choose “Allow” option which is an opt-in for tracking or “Ask App Not to Track” option which is an opt-out from tracking.

You can think about this feature as similar to a permission which shows two options, “Allow cookies” or “Decline cookies” when we visit a website.

To whom is this article for?
If you are going to publish an application in iOS and are targeting users who are on a device version of iOS 14.5 and above. You need to follow the guidelines mentioned in Apple developer documentation — Asking Permission to Track

How to display permission?

To display permission, we need to implement the methods of the framework — App Tracking Transparency

You need to import the framework in your project

#import <AppTrackingTransparency/AppTrackingTransparency.h>

As this framework, methods are available only for iOS 14 and above.

  1. You need to add an if statement to check if the iOS version is 14 and above.
  2. Use the method requestTrackingAuthorizationWithCompletionHandler: 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 requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
switch(status) {
case ATTrackingManagerAuthorizationStatusNotDetermined :
NSLog(@"Unknown consent");
case ATTrackingManagerAuthorizationStatusRestricted :
NSLog(@"Device has an MDM solution applied");
case ATTrackingManagerAuthorizationStatusDenied :
NSLog(@"Denied consent");
case ATTrackingManagerAuthorizationStatusAuthorized :
NSLog(@"Granted consent");
default :
NSLog(@"Unknown");
}
}];
}

The above code will display permission to track the user.

  1. The case ATTrackingManagerAuthorizationStatusAuthorized meant the user has authorised the application.
  2. The case ATTrackingManagerAuthorizationStatusRestricted meant the display permission is not shown to the user and also tracking is restricted.
  3. The case ATTrackingManagerAuthorizationStatusDenied meant the user has not authorised the application.
  4. The case ATTrackingManagerAuthorizationStatusNotDetermined meant the application cannot determine the authorisation status for access.

I hope my article helps you understand how to display permission in iOS using Objective-C.

If you like my articles, please follow me. You can also support me by buying me a coffee.

--

--

Akarsh Seggemu, M.Sc.
Akarsh Seggemu, M.Sc.

Written by Akarsh Seggemu, M.Sc.

IT Team Lead | Post graduate Computer Science from TU Berlin | Telugu writings are found in this account https://medium.com/@akarshseggemu_telugu

No responses yet