AdMob 同意书未显示? [英] AdMob consent form not showing up?

查看:20
本文介绍了AdMob 同意书未显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么 Google 提供的同意书没有显示出来.它说它加载成功,但它没有出现.(我在欧洲,所以我的位置不是问题).我在模拟器和真机上都试过了,我只手动选择了 12 个广告提供商.

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.

这是有问题的代码:

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

推荐答案

您应该在加载表单后呈现.将 form.present 放在 form.load 的完成块中.

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
            [...]
        }
    }
}

这篇关于AdMob 同意书未显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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