Loading UMP consent form in AppDelegate?

473 views
Skip to first unread message

joe...@gmail.com

unread,
Dec 18, 2023, 1:47:52 PM12/18/23
to Google Mobile Ads SDK Developers

Hello. In my iOS project, I load ads in multiple locations: Including AppDelegate (to pre-load Interstials, Banner Ad and App Open Ad). I also load ads (Rewarded and Interstitial) in several other View Controllers throughout the App.


It is my understanding that I must load the form BEFORE Ads load. So I will do this by adding the UMP consent form in AppDelegate didFinishLaunchingWithOptions. My code for this is below. I got this code from this video posted by AdMob on YouTube: https://www.youtube.com/watch?v=EwcrESnAYEI




func gdprJustin() {

     

     let rootVC = self.window?.rootViewController as? UINavigationController

     

     // Create a UMPRequestParameters object.

     let parameters = UMPRequestParameters()

     parameters.tagForUnderAgeOfConsent = false

     

     // ============================

     // ============================

     // FOR DEBUG ONLY

     let debugSettings = UMPDebugSettings()

     debugSettings.testDeviceIdentifiers = [testiPhone]

     debugSettings.geography = .EEA

     parameters.debugSettings = debugSettings

     // ============================

     // ============================

     

     

     // Call this on every app launch!

     UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {

         [weak self] requestConsentError in

         guard let self else {return}

         

         if let error = requestConsentError {

             print("ERROR! \(error.localizedDescription)")

         }

         

         UMPConsentForm.loadAndPresentIfRequired(from: rootVC!) {

             [weak self] loadAndPresentError in

             guard let self else { return }

             

             if let error = loadAndPresentError {

                 print("ERROR! \(error.localizedDescription)")

             }

             

             // Consent gathering process has completed.

             

             if UMPConsentInformation.sharedInstance.canRequestAds {

                 startMobileAds()

             }

             

         }

         

     }

     

     // Attempt to load ads using consent obtained in the previous session.

     if UMPConsentInformation.sharedInstance.canRequestAds {

         startMobileAds()

     }

     

     

}

    

private func startMobileAds() {

     DispatchQueue.main.async {

         guard !self.isMobileAdsStartCalled else {return}

         self.isMobileAdsStartCalled = true

         GADMobileAds.sharedInstance().start()

     }

}


I am calling gdprJustin() in didFinishLaunchingWithOptions (before return true)


My question is… is this proper UMP SDK integration? Do I still need to load the ads AFTER GADMobileAds.sharedInstance().start() in startMobileAds() ??? What about the SEVERAL other GADRequest() load calls I perform outside of AppDelegate?


Thank you for your help.

Mobile Ads SDK Forum Advisor

unread,
Dec 18, 2023, 3:31:01 PM12/18/23
to joe...@gmail.com, google-adm...@googlegroups.com

Hi Joe,

Thank you for contacting the Mobile Ads SDK support team.

I will check with our team regarding your query and one of my team members will reach out to you once we have an update on this. Meanwhile, your patience is highly appreciated.

This message is in relation to case "ref:!00D1U01174p.!5004Q02r2SbY:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


joe...@gmail.com

unread,
Dec 18, 2023, 11:51:24 PM12/18/23
to Google Mobile Ads SDK Developers
Thanks.

Mobile Ads SDK Forum Advisor

unread,
Dec 19, 2023, 12:22:15 PM12/19/23
to joe...@gmail.com, google-adm...@googlegroups.com
Hello,

We recommend calling this code in a view controller because you can reference "self" when passing in the UIViewController object to present message forms; however, if you must call this from the AppDelegate, this is fine although can be error-prone. You can take a look at our GitHub repo for working sample implementations. 

You can load ads as soon as canRequestAds returns true. Prior to loading ads we recommend to initialize the Google Mobile Ads SDK.

For the other GADRequest() load calls performed outside of AppDelegate, you can always use canRequestAds as another layer of verification if you aren't 100% sure that the consent gathering process will have been completed before making those ad requests elsewhere in your app.

Thanks,
Justin
 

ref:!00D1U01174p.!5004Q02r2SbY:ref

joe...@gmail.com

unread,
Dec 20, 2023, 12:49:48 PM12/20/23
to Google Mobile Ads SDK Developers
1. If I take that advice and move the UMP form to the first View Controller that loads, then what happens to all of the ad requests I perform in AppDelegate?? AppDelegate loads before the first View Controller, which is why I moved the form there.

2. "Prior to loading ads we recommend to initialize the Google Mobile Ads SDK." - Where should I initialize Google Mobile Ads SDK.. In AppDelegate? And does THAT call need to be wrapped in any UMP logic?

3. "For the other GADRequest() load calls performed outside of AppDelegate, you can always use canRequestAds as another layer of verification if you aren't 100% sure that the consent gathering process will have been completed before making those ad requests elsewhere in your app." - This advice is technically flawed because the user MUST be able to modify consent at time. Therefore all GADRequest() load calls MUST be in a canRequestAds wrapper. Is that correct?


Overall - my confidence level in properly implementing this UMP is extremely extremely low, and my anxiety and fear in going to production is very high, causing many sleepless nights - it's actually taking a tole on my health and personal wellbeing.
I have so many unanswered questions, and I feel like the documentation and github is not helpful, as the GitHub code specifically tailors the implementation to ONE and ONLY ONE Ad format.
Is there a way I can send my code progress to get audited/checked?

Thank you.

Mobile Ads SDK Forum Advisor

unread,
Dec 20, 2023, 2:29:49 PM12/20/23
to joe...@gmail.com, google-adm...@googlegroups.com
@Joe

1. If those ad requests have to be made from the AppDelegate based on your implementation, you can request consent in the AppDelegate but be aware that not having a "self" reference to a UIViewController may lead to a nil error.

2. See the Request ads section for when to initialize the Google Mobile Ads SDK. Where you initialize (view controller vs. AppDelegate) depends on your implementation.

3. The original answer applies. Yes, the user must be able to modify their consent status, per GDPR. However, this does not affect whether you are able to load ads or not. CanRequestAds returns true if consent has been gathered. If a users modifies their consent to no longer give consent, canRequestAds will still return true because while they do not give consent, their consent was gathered previously. The Google Mobile Ads SDK will determine what ad to return based off their choices (see ad serving modes for more information).

Code audits are beyond our scope of support. The code samples/documentation/videos are made for basic integrations as a baseline with the expectation that the fundamentals can be applied to scaled mobile apps. 

joe...@gmail.com

unread,
Dec 20, 2023, 3:30:58 PM12/20/23
to Google Mobile Ads SDK Developers
Justin, some followups for you.
(Note: I do appreciate your time, I'm just overwhelmingly stressed with this whole process and modification to my Apps which I depend on.)

1. If those ad requests have to be made from the AppDelegate based on your implementation - It's not my implementation.. it's Google's implementation from their official documentation. See here: https://developers.google.com/admob/ios/app-open - I followed those instructions years ago. My App Open ads are all loaded and handled DIRECTLY within AppDelegate as per the documentation.

2. Where you initialize (view controller vs. AppDelegate) depends on your implementation. - Again, Google's official documentation (and just about any tutorial/guide/YouTube video) states to initialize Google Mobile Ads as early as possible: https://developers.google.com/admob/ios/api/reference/Classes/GADMobileAds#-startwithcompletionhandler: - This is done in AppDelegate didFinishLaunchingWithOptions. That's where it's been for years.

3. So then in my other 6 or 7 View Controllers that show ads, do you recommend wrapping the GADRequest .load() calls in canRequestAds? Or is this not a necessary step? I need to know how many View Controllers need to be modified in my Apps.


I need to take a step back and work on hashing this out... With that being said, is the following an acceptable approach?
1. I move the UMP form to the MainViewController (per your recommendation).
3. I post a NotificationCenter inside of startMobileAds() to notify AppDelegate to load the AppOpen, Interstitial and Rewarded ads (Thus i am not making ANY AdMob load calls directly inside AppDelegate didFinishLaunchingWithOptions).
4. I still keep GADMobileAds.sharedInstance().start() within AppDelegate didFinishLaunchingWithOptions and I don't wrap it in any UMP logic?? (Really not sure here..)
5. In ALL OTHER 6 or 7 ViewControllers that display ads, I simply wrap the GADRequest() .load() call in UMPConsentInformation.sharedInstance.canRequestAds (Again... really not sure here)



Thank you.

joe...@gmail.com

unread,
Dec 22, 2023, 11:52:11 AM12/22/23
to Google Mobile Ads SDK Developers
Hello Support team...

Seeing if you can provide insight on my above 3 questions, along with confirming the steps I will take to implement this UMP. Especially the GADMobileAds.sharedInstance().start() call (I do not know if that needs to be in AppDelegate.. before where I call ads in main View Controller.. or does it need to be wrapped in canRequestAds)

Thanks.

Mobile Ads SDK Forum Advisor

unread,
Dec 26, 2023, 2:10:03 PM12/26/23
to joe...@gmail.com, google-adm...@googlegroups.com
Hi Joe,

Did you mean to post your most recent message here? See my response in this thread that answers your previous 3 questions. 

ICYMI, we recommend checking canRequestAds returns true before initializing the Google Mobile Ads SDK. 
Reply all
Reply to author
Forward
0 new messages