In iOS 14 we have a new feature to track IDFA. It’s the default and only available in iOS 14. (Settings > Privacy > Tracking > Allow Apps to Request to Track). I want to check if Allow Apps to Request to Track toggle is ON or OFF using objective-C. How can I do that?

- 175
- 2
- 10
2 Answers
Note that we are only able to access the status of authorization for our own apps using the ATTrackingManager
API. We are not able to read the global setting using any public API.
You can check the status for your app by checking the value for [ATTrackingManager trackingAuthorizationStatus]
:
ATTrackingManagerAuthorizationStatus status = [ATTrackingManager trackingAuthorizationStatus];
switch (status) {
case ATTrackingManagerAuthorizationStatusNotDetermined:
// The user has not yet received an authorization request to authorize access to app-related data that can be used for tracking the user or the device.
break;
case ATTrackingManagerAuthorizationStatusAuthorized:
// The user authorizes access to app-related data that can be used for tracking the user or the device.
break;
case ATTrackingManagerAuthorizationStatusDenied:
// The user denies authorization to access app-related data that can be used for tracking the user or the device.
break;
case ATTrackingManagerAuthorizationStatusRestricted:
// The authorization to access app-related data that can be used for tracking the user or the device is restricted.
break;
}
You can also read the same status after you request authorization from the user:
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// Check for status after request
}];
Also note we can only request for authorization once. It's not recommended to keep asking the user for request.
But if that is really required for your app, a solution for that would be to navigate the user to the Settings instruct them to turn the authorization on for the app:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self checkTrackingAuthorization:ATTrackingManager.trackingAuthorizationStatus];
}
- (void)checkTrackingAuthorization:(ATTrackingManagerAuthorizationStatus) status {
switch (status) {
case ATTrackingManagerAuthorizationStatusAuthorized:
// The user authorizes access to app-related data that can be used for tracking the user or the device.
break;
case ATTrackingManagerAuthorizationStatusNotDetermined:
// The user has not yet received an authorization request to authorize access to app-related data that can be used for tracking the user or the device.
[self requestTrackingAccess];
break;
case ATTrackingManagerAuthorizationStatusDenied:
// The user denies authorization to access app-related data that can be used for tracking the user or the device.
case ATTrackingManagerAuthorizationStatusRestricted:
// The authorization to access app-related data that can be used for tracking the user or the device is restricted.
[self displayTrackingAccessAlert];
break;
}
}
- (void)requestTrackingAccess {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
[self checkTrackingAuthorization:status];
}];
}
- (void)displayTrackingAccessAlert {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Tracking access is required" message:@"Please turn on access to tracking on the settings" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// Open the Settings app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:settingsAction];
[alert addAction:cancelAction];
[alert setPreferredAction:settingsAction];
UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
alertWindow.rootViewController = [[UIViewController alloc] init];
alertWindow.windowLevel = UIWindowLevelAlert + 1;
[alertWindow makeKeyAndVisible];
[alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
}

- 1,532
- 1
- 13
- 37
-
when ATTrackingManagerAuthorizationStatusRestricted triggered? I turn off "Allow apps to request to track" and it switches ATTrackingManagerAuthorizationStatusDenied immediately. – Phạm Ân Feb 03 '21 at 08:38
-
@PhạmÂn The restricted status goes for devices that are under management (MDM). – Jobert Feb 03 '21 at 09:56
You will need to track whether your app has asked for tracking permission (say, store a bool
in NSUserDefaults
.
Then you can check [ATTrackingManager trackingAuthorizationStatus]
. If the status is ATTrackingManagerAuthorizationStatusDenied
but you haven't ever asked for tracking permission (and therefore the user can't have explicitly denied tracking permission to your app) you know that the "Allow apps to request to track" switch is off.
Once you have asked for permission you can no longer determine if the switch is off or if the user has just denied tracking permission to your app explicitly. Either way there isn't much you can do and continually badgering the user to turn tracking on isn't going to endear your app to them.

- 108,386
- 14
- 159
- 186