20

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

Tajinder singh
  • 738
  • 1
  • 9
  • 18
  • Yes, This Problem has been solved. Please follow below two links. https://developer.apple.com/forums/thread/690607 https://developer.apple.com/forums/thread/690762 – Tajinder singh Sep 27 '21 at 06:08

4 Answers4

28

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()
}
Okonov Urmat
  • 319
  • 2
  • 8
9

The problem has been solved, just call it in applicationDidBecomeActive: https://developer.apple.com/forums/thread/690762

Viktor Gavrilov
  • 830
  • 1
  • 8
  • 13
Tajinder singh
  • 738
  • 1
  • 9
  • 18
8

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.

duongvanthai
  • 1,518
  • 1
  • 11
  • 14
  • 1
    calling the tracking in sceneDidBecomeActive worked for me. Thank you! – TharakaNirmana Aug 10 '22 at 03:20
  • 1
    Calling it on sceneDidBecomeActive didn't work for me on iOS 16.1 simulator nor device, but registering for UIApplication.didBecomeActiveNotification did! – yood Nov 08 '22 at 14:01
7

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

Tushar Moradiya
  • 780
  • 1
  • 6
  • 13