ATTrackingManagerAuthorization Not showing

Hi,

I have seen many posts about this but still unable to get our app to prompt users for their permission.

we are a group of scouts trying to develop our first app and none of us have much if any experience and are now totally stuck.

we have tried many ways of putting the code in but the AppDelegate and MainViewController but still unable to get the prompt.

any advice or assistance would be gratefully appreciated

below is the last attempt where we had this code in our MainViewController.

-(void)viewDidLoad {      UIApplication *applicaiton = [UIApplication sharedApplication];

    if (applicaiton.applicationState == UIApplicationStateActive)     {       if (@available(iOS 14, *))       {         ATTrackingManagerAuthorizationStatus status = [ATTrackingManager trackingAuthorizationStatus];

        if (status == ATTrackingManagerAuthorizationStatusNotDetermined)         {           [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status)           {             // Tracking authorization completed. Start loading ads here.

            [[NSOperationQueue mainQueue] addOperationWithBlock:^              {                                        [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];                        }];                      }];                    }                  }                  else                  {                    [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];                    // Fallback on earlier versions                  }                }               [super viewDidLoad]; }  

Answered by BSR_Phil in 706959022

Hi,

Thanks for the quick response, moving the code to viewDidApper has resolved the issue.

:)

Tip:
To help people understand your code, paste it into a code block (using "Paste and Match Style")

-(void)viewDidLoad {
    UIApplication *applicaiton = [UIApplication sharedApplication];
    if (applicaiton.applicationState == UIApplicationStateActive) {
        if (@available(iOS 14, *)) {
            ATTrackingManagerAuthorizationStatus status = [ATTrackingManager trackingAuthorizationStatus];
            if (status == ATTrackingManagerAuthorizationStatusNotDetermined) {
                [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
                    // Tracking authorization completed. Start loading ads here.
                    [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
                        [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];
                    }];
                }];
            }
        } else {
            [[GADMobileAds sharedInstance] startWithCompletionHandler:nil]; // Fallback on earlier versions
        }
    }
    [super viewDidLoad];
}

Did you add the NSUserTrackingUsageDescription key to your info.plist?

e.g.

<key>NSUserTrackingUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to tracking information.</string>

Also, it's probably best not to put the tracking request in your viewDidLoad, as the UI hasn't finished laying-out at this point.
Might be better to have it in viewDidAppear, or on a button action.

Also Also...

  • The system-permission alert will only show when the app’s tracking authorization status is .notDetermined
  • Once the authorization status is set, calling the function will just trigger the completion handler without showing the alert
  • The alert will not be displayed if “Allow Apps to Request to Track” is turned off in the system privacy settings
Accepted Answer

Hi,

Thanks for the quick response, moving the code to viewDidApper has resolved the issue.

:)

ATTrackingManagerAuthorization Not showing
 
 
Q