Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add the AppTrackingTransparency permission to your iOS apps

I am extremely new to iOS, with no iOS development experience at all, however, I've been given a task that's related to preparing for iOS 14+. Based on what I've found https://support.google.com/admanager/answer/9997589, to ensure there's no loss in revenue, I need to do 2 things.

  1. Install the latest Google Mobile Ads SDK for iOS (version 7.64 or later) for AdMob or Ad Manager
  2. Add the AppTrackingTransparency permission to your iOS apps.

I've followed some guides and I'm at the point of dealing with adding the AppTrackingTransparency permission to the iOS app. This is the guide that I'm using, https://developers.google.com/admob/ios/ios14#swift.

I managed to add the key/value, shown below, in Info.plist

<key>NSUserTrackingUsageDescription</key> <string>This identifier will be used to deliver personalized ads to you.</string> 

But this is where I'm hoping to get some help. I think that I still need to add code somewhere to request user permission with AppTrackingTransparency. Based on the guide I think the following code is required to show the App Tracking Transparency dialog box. Question 1, is my assumption correct?

import AppTrackingTransparency import AdSupport ... func requestIDFA() {   ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in     // Tracking authorization completed. Start loading ads here.     // loadAd()   }) } 

Question 2, does the code live in AppDelegate.swift? Or is it really just somewhere that's suitable in the codebase? Thanks.

like image 707
Mark Avatar asked Aug 25 '20 21:08

Mark


People also ask

How do I allow app tracking on my iPhone?

Go to Settings > Privacy > Tracking. The list shows the apps that requested permission to track you. You can turn permission on or off for any app on the list.

Why can't I allow tracking on my iPhone?

Go to Privacy settings to see a list of apps that requested to track your activity. On iPhone, iPad, or iPod touch, go to Settings > Privacy > Tracking. On Apple TV, go to Settings > General > Privacy > Tracking. Tap to turn off or turn on permission to track for a specific app.


2 Answers

For those who might be struggling with the same things, I got the AppTrackingTransparency dialog box to appear with the function,

import AppTrackingTransparency import AdSupport  //NEWLY ADDED PERMISSIONS FOR iOS 14 func 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")             }         }     } } // 

I then simply called the function requestPermission() on the app's login page, so users see the permission dialog before signing in. Without calling the function, the dialog box show in this guide, https://developers.google.com/admob/ios/ios14, doesn't appear for me.

This article has an example github project: https://medium.com/@nish.bhasin/how-to-get-idfa-in-ios14-54f7ea02aa42

like image 81
Mark Avatar answered Oct 08 '22 08:10

Mark


In iOS 15 it can only be requested with ATTrackingManager.requestTrackingAuthorization if the application state is already active, so it should be moved from didFinishLaunchingWithOptions to applicationDidBecomeActive.

like image 31
bartwader Avatar answered Oct 08 '22 09:10

bartwader