App Tracking Transparency Dialog does not appear on iOS

Viewed 12266

Apple reviewer has just rejected my app since ATT request doesn't appear: "We are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.0.1."

My code is as shown below:

if #available(iOS 14, *) {
  ATTrackingManager.requestTrackingAuthorization { (status) in
    //print("IDFA STATUS: \(status.rawValue)")
    FBAdSettings.setAdvertiserTrackingEnabled(true)
  }
}

I implemented this code both in AppDelegate didFinishLaunchingWithOptions and viewDidLoad. ATT permission request appear on iOS 14, but not in iOS 15.

4 Answers

Damn it I fixed it:( This is all about the iOS alert system. I was requesting App Tracking Transparency after a notification request was asked. Once the notification request alert closed, the ATT alert needed to have appeared. It was working fine on iOS 14, but on iOS 15 to display an alert right after another one, it is needed to have a delay period between each other.

Edit: Here is my code that display two alert respectively:

 func setNotification(){
    //Ask for notification permission
    let n = NotificationHandler()
    n.askNotificationPermission {
        //n.scheduleAllNotifications()
        
        //IMPORTANT: wait for 1 second to display another alert
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            if #available(iOS 14, *) {
              ATTrackingManager.requestTrackingAuthorization { (status) in
                //print("IDFA STATUS: \(status.rawValue)")
                //FBAdSettings.setAdvertiserTrackingEnabled(true)
              }
            }
        }
    }
}

And for your convenience here is my NotificaitionHandler class:

import UserNotifications

class NotificationHandler{
//Permission function
func askNotificationPermission(completion: @escaping ()->Void){
    
    //Permission to send notifications
    let center = UNUserNotificationCenter.current()
    // Request permission to display alerts and play sounds.
    center.requestAuthorization(options: [.alert, .badge, .sound])
    { (granted, error) in
        // Enable or disable features based on authorization.
        completion()
    }
}

An Apple person suggests that you request it through applicationDidBecomeActive(_:) in AppDelegate. That's how I fixed the issue for iOS.

import UIKit
import AppTrackingTransparency

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
    func applicationDidBecomeActive(_ application: UIApplication) {
        if #available(iOS 15.0, *) {
            ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                
            })
        }
    }
}

I've changed to call the request from

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
}

to

@available(iOS 13.0, *)
func sceneDidBecomeActive(_ scene: UIScene) {
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
        self.requestPermission()
    }
}

func requestPermission() {
    if #available(iOS 15.0, *) {
            ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                switch status {
                case .authorized:
                    // Tracking authorization dialog was shown
                    // and we are authorized
                    print("Authorized")
                case .denied:
                    // Tracking authorization dialog was
                    // shown and permission is denied
                    print("Denied")
                case .notDetermined:
                    // Tracking authorization dialog has not been shown
                    print("Not Determined")
                case .restricted:
                    print("Restricted ")
                @unknown default:
                   
                }
            })
        }
    }
}

I've changed to call the request from the AppDelegate's applicationDidBecomeActive method and it worked!

The popup is being presented on the first app launch on iOS15.

Related