App Tracking Transparency 弹出窗口不会出现

App Tracking Transparency popup do not appear

我正在尝试在我的应用中实施应用跟踪透明度。我尝试在第一个 ViewControllor 上执行此操作,但它在上传到测试飞行后使应用程序崩溃。

在这之后,我发现了很多信息,这应该在appDelegate中完成,我就是这样做的。当然,我在 Info.plist

中设置了 NSUserTrackingUsageDescription

我试着用 来解决。

在调试器中,我总是看到“未确定”。有人可以帮忙吗?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        requestTrackingPermission()
        GADMobileAds.sharedInstance().start(completionHandler: nil)
        return true
    }

函数

func requestTrackingPermission() {
      if #available(iOS 14, *) {
        // ATTrackingManager.requestTrackingAuthorization { status in
        ATTrackingManager.requestTrackingAuthorization(completionHandler: { 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")
          }
        }
      )}
    }

我找到了如何做到这一点。

添加您的第一个 ViewController

import AppTrackingTransparency
import AdSupport
import UserNotifications

加入viewdidload

  DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                if #available(iOS 14, *) {
                  ATTrackingManager.requestTrackingAuthorization { (status) in
                      print("IDFA STATUS: \(status.rawValue)")
                  }
                }
            }