AppTrackingTransparency... dialog is displayed only one time

2.4k views Asked by At

Starting in 2021, apple is requiring to display a dialog to consent user tracking, so supposedly, even advertising sdks (that tracks a lot of user content for sure) can't be enabled if the user has not accepted that dialog.

https://developer.apple.com/app-store/user-privacy-and-data-use/ https://developer.apple.com/documentation/apptrackingtransparency

Apple gives this function to display the dialog: requestTrackingAuthorization()

the problem is that this function is only displayed one time, so if the user has not accepted it, it is not accepted for ever. Our intention was to close the app if the dialog is not accepted, and display again next time the app is opened, but requestTrackingAuthorization() is not displaying the dialog anymore.

How to solve this situation? How to be able to call that function more than one time?

Imagine that the user has cancelled it, then you are not allowed to display ads never for that user, because ad sdks tracks user content.

2

There are 2 answers

0
Paulw11 On

This is expected and all permission request dialogs in iOS behave in the same way; You get one chance to ask the user directly. The user can subsequently modify their choice in the app settings but you can't keep showing dialogs to them.

If the user declines tracking it doesn't mean you can't show advertising. It simply means that you can't use user tracking data to correlate their activities across your app and other properties and you can't share their location data (if you have it). The ads that are shown won't be targeted to the user and their activities in your app won't be used to affect the ads they see elsewhere.

I am pretty sure your plan would have resulted in your app being rejected anyway. The app has to function regardless of the user tracking decision taken by the user.

0
Jobert On

We cannot ask for permission another time. Apple usually limits this kind of action which could be very annoying for the users if used out of control.
But if that is really required for your app, a solution for that would be to navigate the user to the Settings instruct them to turn the authorization on for the app:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    
    checkTrackingAuthorization(ATTrackingManager.trackingAuthorizationStatus)
}

private func checkTrackingAuthorization(_ status: ATTrackingManager.AuthorizationStatus) {
    switch status {
    case .authorized: break
        // Access is grantted
    case .notDetermined: requestTrackingAccess()
        // The permission was not asked before
    case .denied, .restricted: displayTrackingAccessAlert()
    default: break
        // Unexpected status (there may be additional unknown values added in the future)
    }
}

private func requestTrackingAccess() {
    ATTrackingManager.requestTrackingAuthorization { [weak self] status in
        self?.checkTrackingAuthorization(status)
    }
}

private func displayTrackingAccessAlert() {
    let alert = UIAlertController(title: "Tracking access is required", message: "Please turn on access to tracking on the settings", preferredStyle: .alert)
    let settingsAction = UIAlertAction(title: "Settings", style: .default, handler: { action in
        // Open the Settings app
        UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
    })
    let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
    
    alert.addAction(settingsAction)
    alert.addAction(cancelAction)
    alert.preferredAction = settingsAction
    
    present(alert, animated: true, completion: nil)
}