swiftuiios-privacy-settingsattrackingmanager

Apple Tracking Request not appearing in beta testing, app keeps getting rejected for publication


I implemented the Apple Privacy Tracking Request on my app, and I appears whenever I test it in my real device - it appears over the first screen of the OnBoarding. However, after I archive and send it to beta testing, it just doesn't show-up. I thought it might just be a bug due to the first screens of the TestFlight beta-test, but the people from the App Store keep rejecting it on the basis that I supposedly don't have the Apple Tracking Request in place. Can you help?

Here is what I've done.

import Foundation
import SwiftUI
import GoogleMobileAds
import AppTrackingTransparency
import AdSupport

@main struct ERappApp: App {
    @StateObject private var store = PatientStore()
    @StateObject private var profstore = ProfileStore()
    @AppStorage("_shouldShowOnboarding") var shouldShowOnboarding: Bool = true
    var body: some Scene {
        WindowGroup {
            TabView {
                [...]
            }
            .onAppear {
                if #available(iOS 14, *) {
                    // Display permission to track
                    ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                        switch status {
                        case .notDetermined:
                            print("Unknown consent")
                        case .restricted:
                            print("Device has an MDM solution applied")
                        case .denied:
                            print("Denied consent")
                        case .authorized:
                            print("Granted consent")
                        default:
                            print("Unknown")
                        }
                    })
                }
                PatientStore.load { result in
                    switch result {
                    case .failure(let error):
                        fatalError(error.localizedDescription)
                    case .success(let cards):
                        store.cards = cards
                    }
                }
                ProfileStore.load { result in
                    switch result {
                    case .failure(let error):
                        fatalError(error.localizedDescription)
                    case .success(let prof):
                        profstore.prof = prof
                    }
                }
            }
            .fullScreenCover(isPresented: $shouldShowOnboarding,content: {
                OnBoardingView(shouldShowOnboarding: $shouldShowOnboarding)
            })
            
        }
    }
}



Solution

  • Changed this way, works fine now.

    .onAppear {
                    if #available(iOS 14, *) {
                        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                            ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                                switch status {
                                case .notDetermined:
                                    print("Unknown consent")
                                case .restricted:
                                    print("Device has an MDM solution applied")
                                case .denied:
                                    print("Denied consent")
                                case .authorized:
                                    print("Granted consent")
                                default:
                                    print("Unknown")
                                }
                            })
                        }
                            
                    }
                    PatientStore.load { result in
                        switch result {
                        case .failure(let error):
                            fatalError(error.localizedDescription)
                        case .success(let cards):
                            store.cards = cards
                        }
                    }
                    ProfileStore.load { result in
                        switch result {
                        case .failure(let error):
                            fatalError(error.localizedDescription)
                        case .success(let prof):
                            profstore.prof = prof
                        }
                    }
                }