Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Can't Get a Working Example of the Consent Form #28

Open
LloydDavid opened this issue Jul 9, 2018 · 7 comments
Open

Can't Get a Working Example of the Consent Form #28

LloydDavid opened this issue Jul 9, 2018 · 7 comments

Comments

@LloydDavid
Copy link

LloydDavid commented Jul 9, 2018

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
        }
    }
}
@GDGapps
Copy link

GDGapps commented Jul 19, 2018

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

@LloydDavid
Copy link
Author

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

@GDGapps
Copy link

GDGapps commented Jul 20, 2018

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

@LloydDavid
Copy link
Author

LloydDavid commented Jul 20, 2018

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

@GDGapps
Copy link

GDGapps commented Jul 21, 2018

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

@LloydDavid
Copy link
Author

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

@itzonator
Copy link

itzonator commented Mar 14, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants