googleads-consent-sdk-ios icon indicating copy to clipboard operation
googleads-consent-sdk-ios copied to clipboard

Can't Get a Working Example of the Consent Form

Open LloydDavid opened this issue 6 years ago • 7 comments

Hello, I can't get a working example of the consent pop-up, below is how far I get and no form shows on the view controller, please show a working example, I was expecting a working example of the form in the github repo like admob ad examples so now i'm stuck after adding the code below from here: https://developers.google.com/admob/ios/eu-consent

import PersonalizedAdConsent import UIKit

class FirstOnBoardingViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad()

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

   //collect consent
    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

    //load consent form
    form.load {(_ error: Error?) -> Void in
        print("Load complete.")
        if let error = error {
            // Handle error.
            print("Error loading form: \(error.localizedDescription)")
        } else {
            // Load successful.
        }
    }

    //show consent form
    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.
        } else {
            // Check the user's consent choice.
            _ =
                PACConsentInformation.sharedInstance.consentStatus
        }
    }
}

LloydDavid avatar Jul 09 '18 15:07 LloydDavid

Hello,

you have to put the //show consent form after // Load successful.

So like this

 //load consent form
    form.load {(_ error: Error?) -> Void in
        print("Load complete.")
        if let error = error {
            // Handle error.
            print("Error loading form: \(error.localizedDescription)")
        } else {
            // Load successful.

             //show consent form
             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.
             } else {
                  // Check the user's consent choice.
               _ =  PACConsentInformation.sharedInstance.consentStatus
              }
             }
        }
    }

GDGapps avatar Jul 19 '18 17:07 GDGapps

Hello @GDGapps, thanks for the help o far, I have another issue as shown in the screenshot. screen shot 2018-07-20 at 13 54 14

LloydDavid avatar Jul 20 '18 12:07 LloydDavid

That's Google's fault, I wouldn't bother. It does not impact your app, just wait for them to update the SDK.

GDGapps avatar Jul 20 '18 14:07 GDGapps

Ok @GDGapps , I've also noticed my users would have "app settings" which they can change? But how do I set that up? Please see image below. And got this error in the xcode debug area: Reading from public effective user settings.

--- Error --- Load complete. Error loading form: Error: no information available. Successful call to -[PACConsentInformation requestConsentInfoUpdateForPublisherIdentifiers:completionHandler:] required before using this form. --- Error ---

screen shot 2018-07-20 at 22 28 48

LloydDavid avatar Jul 20 '18 21:07 LloydDavid

@LloydDavid just put a button somewhere in the settings and when the user touches the button have this:

PACConsentInformation.sharedInstance.consentStatus = PACConsentStatus.unknown

so that the user's consent status is unknown and you can present the form again with the same code you used the first time

so my code looks like this

   @IBAction func privacyButtonTouched(_ sender: Any) {
        
        PACConsentInformation.sharedInstance.consentStatus = PACConsentStatus.unknown
        
        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: "yourWebsiteURL"),
                        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 {
                            
                            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.
                                    

                                   //buy the pro Version
                                }
                            }
                        }
                    }
                }
            }
        }
    }

GDGapps avatar Jul 21 '18 08:07 GDGapps

@GDGapps Thanks dude, I'll implement it when I can, I'll let you know about any further issues.

LloydDavid avatar Jul 21 '18 09:07 LloydDavid

Hello, when attempt to show form of this 1.3 version of the Consent SDK, Xcode throws a very strange error:

Consent SDK error

More specifically, this line of code is throwing that error:

PACConsentStatus *status = PACConsentInformation.sharedInstance.consentStatus;

Error: *Cannot initialize a variable of type 'PACConsentStatus ' with an rvalue of type 'PACConsentStatus'

Now, what's triggering this error and is that a bug with the Consent SDK?

Xcode Version 10.1 (10B61) used!

Please advice! @LloydDavid @GDGapps @stephenn @dberlin

itzonator avatar Mar 14 '19 08:03 itzonator