如何将 AppTrackingTransparency 权限添加到您的 iOS 应用程序 [英] How to add the AppTrackingTransparency permission to your iOS apps

查看:37
本文介绍了如何将 AppTrackingTransparency 权限添加到您的 iOS 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 iOS 非常陌生,完全没有 iOS 开发经验,但是,我接到了一个与准备 iOS 14+ 相关的任务.根据我的发现 https://support.google.com/admanager/answer/9997589,为了确保收入没有损失,我需要做两件事.

I am extremely new to iOS, with no iOS development experience at all, however, I've been given a task that's related to preparing for iOS 14+. Based on what I've found https://support.google.com/admanager/answer/9997589, to ensure there's no loss in revenue, I need to do 2 things.

  1. 为 AdMob 或 Ad Manager 安装最新的 iOS 版 Google 移动广告 SDK(版本 7.64 或更高版本)
  2. 为您的 iOS 应用添加 AppTrackingTransparency 权限.

我遵循了一些指南,现在正在处理将 AppTrackingTransparency 权限 添加到 iOS 应用程序的问题.这是我正在使用的指南,https://developers.google.com/admob/ios/ios14#swift.

I've followed some guides and I'm at the point of dealing with adding the AppTrackingTransparency permission to the iOS app. This is the guide that I'm using, https://developers.google.com/admob/ios/ios14#swift.

我设法在 Info.plist

<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>

但这是我希望得到一些帮助的地方.我认为我仍然需要在某处添加代码以使用 AppTrackingTransparency 请求用户许可.根据指南,我认为需要以下代码来显示 App Tracking Transparency 对话框.问题 1,我的假设正确吗?

But this is where I'm hoping to get some help. I think that I still need to add code somewhere to request user permission with AppTrackingTransparency. Based on the guide I think the following code is required to show the App Tracking Transparency dialog box. Question 1, is my assumption correct?

import AppTrackingTransparency
import AdSupport
...
func requestIDFA() {
  ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
    // Tracking authorization completed. Start loading ads here.
    // loadAd()
  })
}

问题 2,代码是否存在于 AppDelegate.swift 中?或者它真的只是适合代码库中的某个地方?谢谢.

Question 2, does the code live in AppDelegate.swift? Or is it really just somewhere that's suitable in the codebase? Thanks.

推荐答案

对于那些可能遇到相同问题的人,我让 AppTrackingTransparency 对话框与该功能一起出现,

For those who might be struggling with the same things, I got the AppTrackingTransparency dialog box to appear with the function,

import AppTrackingTransparency
import AdSupport

//NEWLY ADDED PERMISSIONS FOR iOS 14
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")
            }
        }
    }
}
//

然后我在应用程序的登录页面上简单地调用了函数 requestPermission(),因此用户在登录前会看到权限对话框.在不调用该函数的情况下,该对话框显示在本指南中,https://developers.google.com/admob/ios/ios14,不会出现我.

I then simply called the function requestPermission() on the app's login page, so users see the permission dialog before signing in. Without calling the function, the dialog box show in this guide, https://developers.google.com/admob/ios/ios14, doesn't appear for me.

本文有一个示例github项目:https://medium.com/@nish.bhasin/how-to-get-idfa-in-ios14-54f7ea02aa42

This article has an example github project: https://medium.com/@nish.bhasin/how-to-get-idfa-in-ios14-54f7ea02aa42

这篇关于如何将 AppTrackingTransparency 权限添加到您的 iOS 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆