Mar*_*ark 24 permissions ads ios swift ios14
我对 iOS 非常陌生,完全没有 iOS 开发经验,但是,我接到了一个与preparing for iOS 14+. 根据我发现的https://support.google.com/admanager/answer/9997589,为了确保收入没有损失,我需要做两件事。
我遵循了一些指南,现在正在处理将 加入AppTrackingTransparency permission到 iOS 应用程序的问题。这是我正在使用的指南, 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>
Run Code Online (Sandbox Code Playgroud)
但这是我希望得到一些帮助的地方。我认为我仍然需要在某处添加代码以使用 AppTrackingTransparency 请求用户许可。根据指南,我认为需要以下代码来显示App Tracking Transparency dialog box. Question 1,我的假设正确吗?
import AppTrackingTransparency
import AdSupport
...
func requestIDFA() {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
// Tracking authorization completed. Start loading ads here.
// loadAd()
})
}
Run Code Online (Sandbox Code Playgroud)
Question 2,代码是否存在AppDelegate.swift?或者它真的只是适合代码库中的某个地方?谢谢。
Mar*_*ark 35
对于那些可能正在为同样的事情苦苦挣扎的人,我让 AppTrackingTransparency 对话框与该功能一起出现,
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")
}
}
}
}
//
Run Code Online (Sandbox Code Playgroud)
然后我简单地requestPermission()在应用程序的登录页面上调用了该函数,因此用户在登录之前会看到权限对话框。在不调用该函数的情况下,该对话框显示在本指南中,https://developers.google.com/admob/ios/ios14,不会出现在我身上。
本文有一个示例github项目:https : //medium.com/@nish.bhasin/how-to-get-idfa-in-ios14-54f7ea02aa42
Pra*_*tti 35
func applicationDidBecomeActive(_ application: UIApplication) {\n if #available(iOS 14, *) {\n ATTrackingManager.requestTrackingAuthorization { status in\n switch status {\n case .authorized:\n print("enable tracking")\n case .denied:\n print("disable tracking")\n default:\n print("disable tracking")\n }\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n提交到 App Store 的所有新应用程序都需要遵循iOS 14.0+ 中的应用程序跟踪透明度准则。这些准则构成新的Apple 隐私准则的一部分。主要想法是让用户控制是否所有应用程序都可以跟踪他们,某些应用程序可以跟踪他们,并使应用程序的隐私政策在下载时透明。:+1: 苹果 :眨眼:
\n这可以通过导航到 来实现<PROJECT_NAME>.xcproject / <PROJECT_NAME>.xcworkspace -> General -> Frameworks, Libraries, and Embedded Content。
NSUserTrackingUsageDescription这是一个需要添加到 的字符串键Info.plist。
ATTrackingManager.requestTrackingAuthorizationWithCompletionHandler:建议在第一次应用程序启动时使用此功能,以确保捕获该值。仅当应用程序是全新安装且用户同意状态未知时,才会显示该提示。
\n对于大多数应用程序,只有在状态被授权激活时才启用跟踪(iOS 15 中的新增功能),如下所示:
\nimport AppTrackingTransparency\n\nclass AppDelegate: UIApplicationDelegate {\n\n func applicationDidBecomeActive(_ application: UIApplication) {\n if #available(iOS 14, *) {\n ATTrackingManager.requestTrackingAuthorization { status in\n switch status {\n case .authorized:\n print("enable tracking")\n case .denied:\n print("disable tracking")\n default:\n print("disable tracking")\n }\n }\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n注意:UI 逻辑需要包装在DispatchQueue.main队列上,因为完成块当前是并发执行的DispatchQueue。
ATTrackingManager.trackingAuthorizationStatus跟踪同意的更改,通过ATTrackingManager.trackingAuthorizationStatus它有4 个可能的枚举值:
ATTrackingManagerAuthorizationStatusAuthorized- 已获得同意。ATTrackingManagerAuthorizationStatusDenied- 拒绝同意。ATTrackingManagerAuthorizationStatusNotDetermined- 未知的同意。ATTrackingManagerAuthorizationStatusRestricted - Device has an MDM solution applied. Recommend handling this the same as consent denied until vendor provides consent explicitly.If you are capturing your own analytics, this step is necessary because the user can toggle consent at any time using iOS Settings.
\nIt\'s safer to disable Firebase Analytics, Flurry Analytics, or other Analytics providers from the configuration on app launch after reading the status value when consent is denied/restricted.
\n\nTo answer your questions:
\n\n
\n- No, Analytics will not access the ad ID if no advertising SDKs are present and
\nAdSupportis not linked. However,SafariServiceson\niOS 11 imports theAdSupportframework, causing device advertisement\nidentifier reporting. #1686 (GH issue #) makes it so that explicit ad\nID access control is required, which is something we need to add on\nthe Firebase side.- Yes, if you\'re using Analytics with an ad framework you should follow Apple\'s guidelines. You may not be able to submit to the App\nStore otherwise.
\n
SO, yes it is possible to work around declaring whether you use analytics, but I don\xe2\x80\x99t advise it.
\nTo be honest, I prefer App Store Analytics over 3rd Party Analytics going forward for an integrated experience over more tracking. However, many companies heavily rely on 3rd party analytics data, and if you aren\'t able to migrate away, transparently declare your analytics usage.
\nAnother ideal strategy would be to fully revamp or rapidly A/B test the app before launching live - use beta modes. Analytics in the App Store is more than enough for live apps.
\nI can\'t quantify the risk for being blacklisted subsequently though, as this is library-specific and also depends on your release workflow (do you check for changes in SDK policies?).
\nWrap
\nif #available(iOS 14.0, *)\nRun Code Online (Sandbox Code Playgroud)\nWherever you call the ATTrackingManager because the request will not complete on older iOS versions . Track consent on older iOS versions with your own backend flags, or locally on the device.
Apple 建议如果您跟踪用户,请尽快实施新的 ATT 要求,因为在此期间您将无法访问 App Store 的新更新,即使生产崩溃也是如此。如果您定期更新应用程序,不仅您的用户会更满意,而且您的应用程序商店排名也会提高。
\n想要在应用程序中切换用户同意吗?请参阅此处了解更多信息。
\n小智 34
在iOS 15中,仅当应用程序状态已处于活动状态时才能请求它ATTrackingManager.requestTrackingAuthorization,因此应将其从didFinishLaunchingWithOptions移至applicationDidBecomeActive.
小智 5
我们正在使用 Firebase 和 Facebook,为了让应用程序获得批准,我们将这两个调用都置于 ATT 保护“后面”,即:
对于 Facebook(来自 AppDelegate):
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
if status == .authorized {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
对于 Firebase:
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
if status == .authorized {
Analytics.logEvent(eventName, parameters: [:])
}
}
}
Run Code Online (Sandbox Code Playgroud)
至于通知的 firebase 令牌,我们没有将它们包含在保护后面,因此没有问题。
| 归档时间: |
|
| 查看次数: |
23831 次 |
| 最近记录: |