Reputation: 3738
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.
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.
Upvotes: 70
Views: 116286
Reputation: 1
I followed some of the answers here but the only working one was writing the ATTrackingManager.requestTrackingAuthorization in the ViewController.swift.
In Info.plist, I wrote:
<key>NSUserTrackingUsageDescription</key>
<string>We use this data to provide you with a better advertising experience.</string>
And in the ViewController.swift, I wrote:
import AppTrackingTransparency
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
requestTrackingPermission()
}
func requestTrackingPermission() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .notDetermined:
print("Tracking authorization not determined")
case .restricted:
print("Tracking authorization restricted")
case .denied:
print("Tracking authorization denied")
case .authorized:
print("Tracking authorization granted")
@unknown default:
print("Unknown tracking authorization status")
}
}
}
else {
print("AppTrackingTransparency framework not available on this iOS version")
}
}
To test if the request appear, you should not test it on the simulator.
Upvotes: 0
Reputation: 9915
func applicationDidBecomeActive(_ application: UIApplication) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
print("enable tracking")
case .denied:
print("disable tracking")
default:
print("disable tracking")
}
}
}
}
All new apps submitted to the App Store need to follow App Tracking Transparency guidelines in iOS 14.0+. These guidelines form part of new Apple privacy guidelines. The main idea is for users to be given control of whether all apps can track them, some apps can track them, and make the privacy policies of the apps Transparent on download. :+1: Apple :wink:
This is possible by navigating to <PROJECT_NAME>.xcproject / <PROJECT_NAME>.xcworkspace -> General -> Frameworks, Libraries, and Embedded Content
.
NSUserTrackingUsageDescription
This is a String key that needs to be added to Info.plist
/ the Xcode project's Information
tab (.xcodeproj or .xcworkspace files).
ATTrackingManager.requestTrackingAuthorizationWithCompletionHandler:
This function is advised on the first app launch to ensure the value is captured. The prompt only shows if the app is a fresh install and the user consent status is unknown.
For the majority of applications, only enable tracking if the status is authorized on becoming active (new in iOS 15), as below:
import AppTrackingTransparency
class AppDelegate: UIApplicationDelegate {
func applicationDidBecomeActive(_ application: UIApplication) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
print("enable tracking")
case .denied:
print("disable tracking")
default:
print("disable tracking")
}
}
}
}
}
NOTE: UI Logic needs to be wrapped on the DispatchQueue.main
queue because the completion block currently executes on a concurrent DispatchQueue
.
ATTrackingManager.trackingAuthorizationStatus
Track changes to consent via ATTrackingManager.trackingAuthorizationStatus
which has 4 possible enum values:
ATTrackingManagerAuthorizationStatusAuthorized
- Granted consent.ATTrackingManagerAuthorizationStatusDenied
- Denied consent.ATTrackingManagerAuthorizationStatusNotDetermined
- Unknown consent.ATTrackingManagerAuthorizationStatusRestricted
- Device has an MDM solution applied. Recommend handling this the same as consent denied until vendor provides consent explicitly.If you are capturing your own analytics, this step is necessary because the user can toggle consent at any time using iOS Settings.
Firebase
, Adobe
, mParticle Analytics
, or other Analytics providers from the configuration on app launch after reading the status value when consent is denied/restricted. This is the safest option.optOut
setting of the framework with anonymised tracking enabled when consent is denied/restricted. e.g. mParticle has this option to make the SDK conform to ATT requirements.Choose one of the three options based on your situation. It's hard to provide advice relevant to all SDKs, so you should consult the documentation to make an informed choice.
To answer your questions:
- No, Analytics will not access the ad ID if no advertising SDKs are present and
AdSupport
is not linked. However,SafariServices
on iOS 11 imports theAdSupport
framework, causing device advertisement identifier reporting. #1686 (GH issue #) makes it so that explicit ad ID access control is required, which is something we need to add on the Firebase side.- Yes, if you're using Analytics with an ad framework you should follow Apple's guidelines. You may not be able to submit to the App Store otherwise.
SO, yes it is possible to work around declaring whether you use analytics, but I don’t advise it.
App Store Analytics might be enough for smaller apps and has the advantage of being easier to comply with ATT requirements. These are viewable on App Store Connect. Third-party analytics may provide more detailed data and broader coverage, but Apple Analytics delivers a more seamless, integrated experience. However, I realise many companies heavily rely on 3rd party analytics data, and if you aren't able to migrate away, transparently declare your analytics usage.
Another ideal strategy would be to fully revamp or rapidly A/B test the app before launching live - use beta modes. Analytics in the App Store is more than enough for live apps, and makes the app more appealing to customers by clearly declaring tracking permissions at the time of download.
I can't quantify the risk for being blacklisted subsequently though, as this is library-specific and also depends on your release workflow (do you check for changes in SDK policies?).
Wrap
if #available(iOS 14.0, *)
Wherever you call the ATTrackingManager
because the request will not complete on older iOS versions 😅. Track consent on older iOS versions with your own backend flags, or locally on the device.
Apple suggests implementing the new ATT requirements as soon as possible if you track users because you will be blocked from new updates to the App Store in the meantime, even with production crashes. Not only will your users be happier, but your App Store ranking improves if you update your app regularly.
Want to toggle user consent in the app? See here for more info.
Upvotes: 40
Reputation: 2650
For me embedding the dialog into App Delegate applicationDidBecomeActive
wasn't working.
I embedded the well known ATTrackingManager.requestTrackingAuthorization
into my initial viewcontroller.
Upvotes: 0
Reputation: 61
func askPermission() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in
//handled
print(status)
if status == .authorized{
Settings.shared.isAdvertiserTrackingEnabled = true
}
}
}
}
I don't know but for me this piece of code works
Upvotes: 3
Reputation: 811
Calling ATTrackingManager.requestTrackingAuthorization
in the App Delegate applicationDidBecomeActive
function won't be called if you're using Scenes because of this instead use sceneDidBecomeActive(_:)
in the SceneDelegate and make sure you delay for a second else it won't be called for some reason.
func sceneDidBecomeActive(_ scene: UIScene) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
print("enable tracking")
case .denied:
print("disable tracking")
default:
print("default tracking")
}
}
}
})
}
Upvotes: 5
Reputation: 93
I have observed that if the following method
"ATTrackingManager requestTrackingAuthorizationWithCompletionHandler()"
is called from AppDelegate then sometimes "ATTrackingManagerAuthorizationStatusNotDetermined" is returned as a status and an alert is not shown.
My phone's iOS version is "iOS-15.0.2"
As a solution, we can call "requestTrackingAuthorization..." method after splash screen or after appearing LandingPage.
Upvotes: 0
Reputation: 629
We are using Firebase and Facebook, to get the app approved we put both calls "behind" the ATT protection, that is:
For Facebook (from AppDelegate):
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
if status == .authorized {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
}
}
}
For Firebase:
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
if status == .authorized {
Analytics.logEvent(eventName, parameters: [:])
}
}
}
As for the firebase token for the notifications, we did not include them behind the protection and had no issue.
Upvotes: 5
Reputation: 404
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
.
Upvotes: 36
Reputation: 267384
Open info.plist
file, add SKAdNetworkIdentifier
and NSUserTrackingUsageDescription
. The following one is only for Google (Admob), you can find the full list here.
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>cstr6suwn9.skadnetwork</string>
</dict>
</array>
//..
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
Request the ATT dialog. (For simplicity I'm requesting it right after the app loads)
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
//...
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
if (@available(iOS 14.0, *))
{
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// Tracking authorization completed. Start loading ads here.
// [self loadAd];
}];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
Upvotes: 3
Reputation: 3384
According to the link you posted:
https://developers.google.com/admob/ios/ios14#swift.
The main thing to avoid loss of revenue from AdMob is to add this into Info.plist:
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>cstr6suwn9.skadnetwork</string>
</dict>
</array>
I don't know when/if AppTrackingTransparency permission is required. I know Apple say you need it but they don't give a deadline. Google say "If you decide to include App Tracking Transparency" which to me is hinting to not bother!
Upvotes: 4
Reputation: 31
As a completion on @mark answer you also should add permission statement to plist file in key Privacy - Tracking Usage Description
Upvotes: 1
Reputation: 3738
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
Upvotes: 74