[Swift] Acquisition of IDFA on iOS14

What is IDFA

IDFA is an abbreviation for "Identifier for Advertisers", a device ID that Apple randomly assigns to a user's device. Advertisers can use this ID to measure user ad engagement and in-app user behavior to serve customized ads. In other words, it is thanks to this IDFA that you may see ads that you are interested in in the iOS app.

Obtaining IDFA from iOS14

At WWDC 2020, it was announced that iOS 14 will make changes to the handling of IDFA. Since iOS14, it is required to display a dialog to select whether to acquire IDFA before acquiring it.

How to display the IDFA acquisition dialog

1. Add framework

Add the following framework. AdSupport.framework AppTrackingTransparency.framework

Reference link: https://developer.apple.com/documentation/adsupport https://developer.apple.com/documentation/apptrackingtransparency

2. Add wording to info.plist

b1b425f7-b494-2d34-86d9-d7bfd25bdb08.png

Set the wording in Value with "Privacy --Tracking Usage Description" as the Key in info.plist. The wording is reflected in the red frame part of the above image, and it seems that the default wording cannot be changed for other parts.

3. Display dialog

By using ** requestTrackingAuthorization (completionHandler :) ** to display the dialog, it can be implemented as follows.

Swift

if #available(iOS 14, *) {
   ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
      switch status {
      case .authorized:
         //IDFA acquisition
         print("IDFA: \(ASIdentifierManager.shared().advertisingIdentifier)")
         print("success")
      case .denied, .restricted, .notDetermined:
         print("failure")
      @unknown default:
         fatalError()
      }
   })
}       

Recommended Posts

[Swift] Acquisition of IDFA on iOS14
iOS 14.4 IDFA Summary
SKStoreReviewController implementation memo in Swift UI of iOS14
Research on Swift Optional
[iOS] Measures to prevent the expected operation of Status Bar height acquisition on iPhone12 mini
[Swift 5] Select a date with the IDate Picker on iOS14
[Swift] Simple implementation of UIImageView
[Swift] Types of types-Basic knowledge-
[Swift] Implementation of ultra-simple billing
Use Swift Package on Playground
[IOS] canOpenURL becomes false on iOS14
ATDD development on iOS (basic)
Tips around resources of Swift Package Manager for library creators for iOS
[Swift] How to dynamically change the height of the toolbar on the keyboard
[Swift UI] How to get the startup status of the application [iOS]