IOS14 tracking permission for apps compiled with IOS 13

Viewed 3177

In IOS14 in order to use Advertising Identifier you need to request for permission but what's the behaviour for apps already available on AppStore (Compiled with IOS13 SDK)?

I have updated a device to IOS14 Beta 4 and downloaded app from AppStore. Once I open the app it's not automatically asking for any tracking permission and Advertising Identifier is 00000-0000-0000.

Does this mean I must submit an app update compiled with IOS14 SDK and request for tracking permission otherwise Advertising Identifier won't be available?

2 Answers

Yes, you need to submit a new app version. It will not automatically ask for tracking permission because it should be instantiated via developer. Therefore, you need to use AppTrackingTransparency framework and ask for a user permission:

if #available(iOS 14, *) {
   ATTrackingManager.requestTrackingAuthorization { _ in
   }
} else {
   // Fallback on earlier versions
}

You have to implement AppTrackingTransparency from ios 14 to show tracking permission. From this implementation, you can collect the IDFA.

Do this in AppDelegate

import AppTrackingTransparency

in didFinishLaunchingWithOptions launchOptions write a function like this

     if #available(iOS 14, *) {
self.requestIDFAPermission() 
}

then write this function

   func requestIDFAPermission() {
    if #available(iOS 14, *) {
        let semaphore = DispatchSemaphore(value: 0)
        DispatchQueue.main.async {
            ATTrackingManager.requestTrackingAuthorization { (status) in
                if (status == .authorized) {
                    let idfa = ASIdentifierManager.shared().advertisingIdentifier
                    print("IDFA: " + idfa.uuidString)
                } else {
                    print("Failed to get IDFA")
                }
                semaphore.signal()
            }
        }
        semaphore.wait()
    }
}

There is one more thing. You should add Privacy - Tracking Usage Description in the Plist.

Related