How do i determine if a user has given consent to show them personalised ads on iOS using admob?

835 views Asked by At

Im currently implementing Admob into my iOS app. You can see the implementation under. While implementing a had a few question and after a lot of searching and documentation reading i still didn't have the answers. So here are my questions

  1. Should i show the ATT prompt fist then the GDPR form or should it be the other way around? Dose this matter?
  2. If a user consent to the ATT prompt and then don't consent to the GRDB form, how do i know not to serve personalised ads? 'UMPConsentInformation.sharedInstance.consentStatus' only returns status = obtained. It doesn't give me any information if the user consented to personalised ads or not.

I want to serve personalised ads if possible, otherwise i want to serve non personalised ads.

func requestIDFA() {
    ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
        requestLatestConsentForm()
    })
}

func requestLatestConsentForm() {
    let parameters = UMPRequestParameters()
    
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
        with: parameters,
        completionHandler: { error in
            if error != nil {
                // Handle the error.
            } else {
                if UMPConsentInformation.sharedInstance.formStatus == UMPFormStatus.available {
                    self.loadForm()
                }
            }
        })
}

func loadForm() {
    UMPConsentForm.load(completionHandler: { form, loadError in
        if loadError != nil {
            // Handle the error.
        } else {
            let status = UMPConsentInformation.sharedInstance.consentStatus
            if status == UMPConsentStatus.required {
                form?.present(
                    from: UIApplication.shared.windows.first!.rootViewController! as UIViewController,
                    completionHandler: { dismissError in
                        if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.obtained {
                            GADMobileAds.sharedInstance().start(completionHandler: nil)
                        }
                    })
            } else {
                // Keep the form available for changes to user consent.
            }
        }
    })
}
0

There are 0 answers