ATTrackingManager stopped working in iOS 15

Viewed 6710

ATTrackingManager.requestTrackingAuthorization stopped working on ios 15. Application rejected from Apple.

4 Answers

According to the discussion in Apple Developer Forum, you need to add delay for about one second when calling requestTrackingAuthorization. https://developer.apple.com/forums/thread/690607

Example:

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
          ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
        // Tracking authorization completed. Start loading ads here.
        // loadAd()
      })
})

P.S. Also if you have requesting push notification permission, firstly you need request push notification then request tracking authorization with a delay =>

    private func requestPushNotificationPermission() {
    let center = UNUserNotificationCenter.current()
    UNUserNotificationCenter.current().delegate = self
    center.requestAuthorization(options: [.sound, .alert, .badge], completionHandler: { (granted, error) in
        if #available(iOS 14.0, *) {
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
                ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                    // Tracking authorization completed. Start loading ads here.
                    // loadAd()
                })
            })
        }})
    UIApplication.shared.registerForRemoteNotifications()
}

Follow by apple doc:

Calls to the API only prompt when the application state is UIApplicationStateActive.

So, we need to call ATTrackingManager.requestTrackingAuthorization on applicationDidBecomeActive of AppDelegate.

But If you're using scenes (see Scenes), UIKit will not call this method. Use sceneDidBecomeActive(_:) instead to restart any tasks or refresh your app’s user interface. UIKit posts a didBecomeActiveNotification regardless of whether your app uses scenes.

So, my approach is to register on addObserver on didFinishLaunchingWithOptions such as:

NotificationCenter.default.addObserver(self, selector: #selector(handleRequestEvent), name: UIApplication.didBecomeActiveNotification, object: nil)

on handleRequestEvent:

requestPermission() // func call ATTrackingManager.requestTrackingAuthorization NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)

Hope this helps. It's work for me.

Make sure your iPhone's Settings -> Privacy -> Tracking is enabled. Otherwise, it won't prompt for request Aurthorization.

Related