How to request IDFA and update AdMob for iOS 14

Published by @SoNiceInfo at 8/19/2020


Display of Update SwiftUI App with AdMob for IDFA and AppTrackingTransparency of iOS 14

Background to this article.

For now, if you want to implement it, please skip to How to update for iOS 14.

User permission is required to use IDFA on iOS 14

Ad publishers, such as AdMob, use an identifier called IDFA to uniquely identify a device.
It's a mechanism to deliver ads of interest to users. However, in order to use IDFA from iOS 14, you need to ask the user's permission for it in the app.

Update to Google Mobile Ads SDK for iOS 14

Google released the Google Mobile Ads SDK for iOS 14 on 8/11.
. The update also supports SKAdNetwork, Apple's required ad network instead of IDFA.
In this article, I'll show you how to update your iOS app created before iOS 13 so that it can continue to serve ads on iOS 14.

How to update for iOS 14

  1. Update Google Mobile Ads SDK to 7.64.0 or higher.
  2. Display the AppTrackingTransparency dialog (that asks for permission to use IDFA)

Update the Google Mobile Ads SDK

Update Google Mobile Ads SDK to 7.64.0 or higher to be able to serve ads on iOS 14.
. Open Terminal and update the pod in the app directory.

$ cd YOUR_APP_PROJECT
$ pod update Google-Mobile-Ads-SDK

Add NSUserTrackingUsageDescription to Info.plist

Display of Add NSUserTrackingUsageDescription to Info.plist

This will display a dialog asking the user for permission to use IDFA for in-app advertising.
Open info.plist in Xcode and enter "Privacy - Tracking Usage Description" in the Key field.
. For Value, enter the text you want to convey to the user.

The relevant section looks like this when you open it in the text app.

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

Add SKAdNetworkItems to Info.plist

Add SKAdNetworkItems to Info.plist画面

This is where Google makes the SKAdNetwork available to you.
The SKAdNetwork is used to serve ads using Apple's SKAdNetwork, even if the user refuses to obtain an IDFA.
. The values you set here may change in the future, so check the official Google website.

The relevant section looks like this when you open it in the text app.

<key>SKAdNetworkItems</key>
  <array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string>cstr6suwn9.skadnetwork</string>
    </dict>
  </array>

Show AppTrackingTransparency dialog & Initialize Google Mobile Ads SDK

AppTrackingTransparency dialog diplay

From here you can ask the actual user to give you permission to use IDFA.
. Use ATTrackingManager.requestTrackingAuthorization to make the dialog appear.
. Please check details of status at ATTrackingManager.AuthorizationStatus
If a user permits the use of IDFA, ads using IDFA are served, and if they are rejected, ads using SKAdNetwork are served.

import AppTrackingTransparency
import AdSupport
import GoogleMobileAds

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        if #available(iOS 14, *) {
            ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                GADMobileAds.sharedInstance().start(completionHandler: nil)
            })
        } else {
            // Fallback on earlier versions
            GADMobileAds.sharedInstance().start(completionHandler: nil)
        }
        return true
    })
})

References

Preparing your app for iOS 14+ - Google AdMob ヘルプ
Prepare for iOS 14+  |  Google Developers