2

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.

Emre Gürses
  • 1,992
  • 1
  • 23
  • 28

1 Answers1

3

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

Akbar Khan
  • 2,215
  • 19
  • 27
  • I have been looking for this answer for quite sometime, thank you! Where did you find the info about "IF you are using Appdelegate call it from ApplicationDidBecomeActive and if you are using Scenedelegate call it from SceneDidBecomeActive" – Christopher Haas Oct 20 '21 at 19:08
  • IF you are using Appdelegate call it from ApplicationDidBecomeActive and if you are using Scenedelegate call it from SceneDidBecomeActive ! Thank you! – user3788747 Dec 09 '21 at 14:26