PITFALL: App Tracking Transparency prompt not showing

in #iphone3 years ago

An App Store reviewer rejected my app update because the ATT prompt is not showing up (it did work in the last update).

We're looking forward to completing our review, but we need more information to continue. Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.1.

It turns out there is indeed a bug.

There's a change in requestTrackingAuthorization starting from iOS 15.

Calls to the API only prompt when the application state is UIApplicationStateActive. The authorization prompt doesn’t display if another permission request is pending user confirmation. Concurrent requests aren’t preserved by iOS, and calls to the API through an app extension don’t prompt.

Ah.. So the issue is that my app was calling it (during launch) when the applicationState is inactive, hence the prompt is not shown.

Quick Solution

You can use your app delegate applicationDidBecomeActive.

Or if you're lazy, simply introduce a delay.

if #available(iOS 14, *) {
    DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
        ATTrackingManager.requestTrackingAuthorization { status in
        }
    }
}

This is an Apple bug, started by Apple Engineers, and reported by App Reviewer.