Admob IOS swift GDPR consent

1.1k views Asked by At

I'm new to swift and iOS programming. I want to add Admob consent/GDPR option to my app, So I've setup an ad box and can display a test add, but need to add consent option next.

I've read https://developers.google.com/admob/ios/eu-consent

but it's not clear to me, can anyone show me an example of code to do this step by step, or point me to GitHub source where it has been done.

Thanks

1

There are 1 answers

4
KingJulian On

Can you please show an example of what you have tried that isn't working for you?

As I am unable to see your code example to see what you're doing or not doing, I'll give an example based on the docs.

import PersonalizedAdConsent

...

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    PACConsentInformation.sharedInstance.
    requestConsentInfoUpdate(
    forPublisherIdentifiers: ["pub-0123456789012345"])
    {(_ error: Error?) -> Void in
      if let error = error {
        // Consent info update failed.
      } else {
        // Consent info update succeeded. The shared PACConsentInformation
        // instance has been updated.
      }
    }

guard let privacyUrl = URL(string: "https://www.your.com/privacyurl"),
  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 {
    // Load successful.
  }
}

//Finally present the consent form
form.present(from: self) { (error, userPrefersAdFree) in
      if let error = error {
        // Handle error.
      } else if userPrefersAdFree {
        // User prefers to use a paid version of the app.
      } else {
        // Check the user's consent choice.
        let status =
             PACConsentInformation.sharedInstance.consentStatus
      }
    }

      }