【问题标题】:App Tracking Transparency popup do not appearApp Tracking Transparency 弹出窗口不出现
【发布时间】:2022-01-18 15:11:52
【问题描述】:

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

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

我试图通过this post 来解决这个问题。

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

    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")
          }
        }
      )}
    }

【问题讨论】:

  • 您应该在 ViewControllers 而不是应用委托中请求权限。
  • 我试了几次,但如果没有按钮或类似的东西,它就不起作用。能否举例说明如何实现?

标签: swift admob google-ads-api privacy


【解决方案1】:

我找到了方法。

添加你的第一个 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)")
                  }
                }
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-22
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2022-11-03
    • 2022-06-11
    • 1970-01-01
    相关资源
    最近更新 更多