简体   繁体   中英

Swift - App Tracking Transparency - No Show Pop-Up due to ‘Allow Apps to Request to Track’ Greyed Out

As you now, Apple changed rules in mobile development in terms of Ads and tracking.

Apple prepared new Beta 14.5 iOS version. With this version tracking will be restricted. So, I wanted to simulate this option in my apps.

When I updated my phone to 14.5 iOS version(Beta) and Xcode(Version 12.5 beta 3 (12E5244e)), 'Allow Apps to Request to Track' option is greyed out, and can not changed.

So, in below code snipped, always return .restricted due to the above issue.

func requestPermission() {
    if #available(iOS 14, *) {
        ATTrackingManager.requestTrackingAuthorization { status in
            switch status {
            case .authorized:
                // Tracking authorization dialog was shown
                // and we are authorized
                print("Authorized")

                // Now that we are authorized we can get the IDFA
                print(ASIdentifierManager.shared().advertisingIdentifier)
            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:
                print("Unknown")
            }
        }
    } else {
        // Fallback on earlier versions
    }
}

So, I am in stuck because of this issue. Do you have any option/suggession?

Not: In iOS 14.2 version everything was good, and 'Allow Apps to Request to Track' option could be changed. But now It's greyed out.

This worked for me

func requestIDFA() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            if #available(iOS 14, *) {
                
                ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                    // Tracking authorization completed. Start loading ads here.
                })
            } else {
                // Fallback on earlier versions
            }
        }
    }

IF you are using Appdelegate call it from ApplicationDidBecomeActive and if you are using Scenedelegate call it from SceneDidBecomeActive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM