问题
I don't understand why the Google-rendered consent form is not showing up. It says that it loads successfully, but then it doesn't show up. (I am in Europe, so my location is not a problem). I have tried both on simulators and real devices, I have manually selected only 12 ad providers.
Here is the code in question:
PACConsentInformation.sharedInstance.debugIdentifiers = ["4FDF7D7F-8F56-4E65-8570-103100943386"]
PACConsentInformation.sharedInstance.debugGeography = PACDebugGeography.EEA
PACConsentInformation.sharedInstance.requestConsentInfoUpdate(forPublisherIdentifiers: ["pub-5765803665103285"]){
(_ error: Error?) -> Void in
if let error = error {
// Consent info update failed.
print(error)
} else {
// Consent info update succeeded. The shared PACConsentInformation
// instance has been updated.
if PACConsentInformation.sharedInstance.consentStatus == PACConsentStatus.unknown {
guard let privacyUrl = URL(string: "http://www.gdgapps.altervista.org/index.html/gdg-privacy.html"),
let form = PACConsentForm(applicationPrivacyPolicyURL: privacyUrl) else {
print("incorrect privacy URL.")
return
}
form.shouldOfferPersonalizedAds = true
form.shouldOfferNonPersonalizedAds = true
form.shouldOfferAdFree = true
form.load {(_ error: Error?) -> Void in
print("Load complete.")
if let error = error {
// Handle error.
print("Error loading form: \(error.localizedDescription)")
} else {
print("Load successful.")
}
}
form.present(from: self) { (error, userPrefersAdFree) in
if error != nil {
// Handle error.
} else if userPrefersAdFree {
// User prefers to use a paid version of the app.
//TODO: buy pro version
} else {
// Check the user's consent choice.
let status = PACConsentInformation.sharedInstance.consentStatus
// TODO: show ads
}
}
} else if PACConsentInformation.sharedInstance.consentStatus == PACConsentStatus.nonPersonalized || PACConsentInformation.sharedInstance.consentStatus == PACConsentStatus.personalized{
print("ads")
self.bannerView.isHidden = false
self.tableBasso.constant = 50
self.bannerView.adUnitID = "ca-app-pub-5765803665103285/9440944250"
self.bannerView.rootViewController = self
let request = GADRequest()
if PACConsentInformation.sharedInstance.consentStatus == PACConsentStatus.nonPersonalized {
let extras = GADExtras()
extras.additionalParameters = ["npa": "1"]
request.register(extras)
}
self.bannerView.load(request)
}
}
}
}
回答1:
You should present the form after it's loaded. Put form.present
inside the completion block of form.load
.
form.load { [weak self] error in
print("Load complete.")
if let error = error {
print("Error loading form: \(error.localizedDescription)")
} else {
guard let strongSelf = self else { return }
form.present(from: strongSelf) { error, userPrefersAdFree in
[...]
}
}
}
来源:https://stackoverflow.com/questions/51427003/admob-consent-form-not-showing-up