我正在尝试使用UserMessagingPlatform
来请求跟踪许可和欧盟 GDPR 同意。它要求在模拟器上运行时进行跟踪,但未显示欧盟同意对话框。怎么了?我在 AdMob 的资金选择中创建了这两个选项。
这是在 iOS 和 Swift 上。
private func requestIDFA() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
// Tracking authorization completed. Start loading ads here.
self.showConsentInformation()
})
} else {
// Fallback on earlier versions
}
}
private func showConsentInformation() {
let parameters = UMPRequestParameters()
// false means users are not under age.
parameters.tagForUnderAgeOfConsent = false
let debugSettings = UMPDebugSettings()
debugSettings.geography = UMPDebugGeography.EEA
parameters.debugSettings = debugSettings
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
with: parameters,
completionHandler: { error in
if error != nil {
// Handle the error.
} else {
// The consent information state was updated.
// You are now ready to check if a form is
// available.
let formStatus = UMPConsentInformation.sharedInstance.formStatus
if formStatus == UMPFormStatus.available {
self.loadForm()
}
}
})
}
func loadForm() {
UMPConsentForm.load(
completionHandler: { form, loadError in
if loadError != nil {
// Handle the error
} else {
// Present the form
if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required {
form?.present(from: UIApplication.shared.windows.first!.rootViewController! as UIViewController, completionHandler: { dimissError in
if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.obtained {
// App can start requesting ads.
// initGoogleMobileAds()
}
})
}
}
})
}