From 69fb7c66637e935dc07a08e6bc8cc2ed1a5dc468 Mon Sep 17 00:00:00 2001 From: Justin Malandruccolo Date: Thu, 17 Oct 2024 11:35:03 -0700 Subject: [PATCH] Add includecode comments for UMP SDK integration PiperOrigin-RevId: 686987300 --- .../BannerExample/GoogleMobileAdsConsentManager.m | 6 ++++++ .../admob/BannerExample/BannerExample/ViewController.m | 8 ++++++++ .../BannerExample/GoogleMobileAdsConsentManager.swift | 6 ++++++ .../BannerExample/BannerExample/ViewController.swift | 8 ++++++++ 4 files changed, 28 insertions(+) diff --git a/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m b/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m index 17686087..dc9611f6 100644 --- a/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m +++ b/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m @@ -35,10 +35,12 @@ - (BOOL)canRequestAds { return UMPConsentInformation.sharedInstance.canRequestAds; } +// [START is_privacy_options_required] - (BOOL)isPrivacyOptionsRequired { return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == UMPPrivacyOptionsRequirementStatusRequired; } +// [END is_privacy_options_required] - (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)viewController consentGatheringComplete: @@ -50,6 +52,7 @@ - (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)v // debugSettings.geography = UMPDebugGeographyEEA; parameters.debugSettings = debugSettings; + // [START gather_consent] // Requesting an update to consent information should be called on every app launch. [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters @@ -68,13 +71,16 @@ - (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)v }]; } }]; + // [END gather_consent] } - (void)presentPrivacyOptionsFormFromViewController:(UIViewController *)viewController completionHandler: (void (^)(NSError *_Nullable))completionHandler { + // [START present_privacy_options_form] [UMPConsentForm presentPrivacyOptionsFormFromViewController:viewController completionHandler:completionHandler]; + // [END present_privacy_options_form] } @end diff --git a/Objective-C/admob/BannerExample/BannerExample/ViewController.m b/Objective-C/admob/BannerExample/BannerExample/ViewController.m index 72a6d2d9..8d634bf8 100644 --- a/Objective-C/admob/BannerExample/BannerExample/ViewController.m +++ b/Objective-C/admob/BannerExample/BannerExample/ViewController.m @@ -85,6 +85,7 @@ - (void)viewDidLoad { self.bannerView.delegate = self; __weak __typeof__(self) weakSelf = self; + // [START can_request_ads] [GoogleMobileAdsConsentManager.sharedInstance gatherConsentFromConsentPresentationViewController:self consentGatheringComplete:^(NSError *_Nullable consentError) { @@ -101,16 +102,21 @@ - (void)viewDidLoad { if (GoogleMobileAdsConsentManager.sharedInstance.canRequestAds) { [strongSelf startGoogleMobileAdsSDK]; } + // [START_EXCLUDE] + // [START add_privacy_options] strongSelf.privacySettingsButton.enabled = GoogleMobileAdsConsentManager.sharedInstance .isPrivacyOptionsRequired; + // [END add_privacy_options] + // [END_EXCLUDE] }]; // This sample attempts to load ads using consent obtained in the previous session. if (GoogleMobileAdsConsentManager.sharedInstance.canRequestAds) { [self startGoogleMobileAdsSDK]; } + // [END can_request_ads] } - (void)viewDidAppear:(BOOL)animated { @@ -133,6 +139,7 @@ - (void)viewWillTransitionToSize:(CGSize)size completion:nil]; } +// [START request_ads] - (void)startGoogleMobileAdsSDK { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -141,6 +148,7 @@ - (void)startGoogleMobileAdsSDK { [self loadBannerAd]; }); } +// [END request_ads] - (void)loadBannerAd { // Here safe area is taken into account, hence the view frame is used after the diff --git a/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift b/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7b43d383 100644 --- a/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift @@ -30,9 +30,11 @@ class GoogleMobileAdsConsentManager: NSObject { return UMPConsentInformation.sharedInstance.canRequestAds } + // [START is_privacy_options_required] var isPrivacyOptionsRequired: Bool { return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == .required } + // [END is_privacy_options_required] /// Helper method to call the UMP SDK methods to request consent information and load/present a /// consent form if necessary. @@ -47,6 +49,7 @@ class GoogleMobileAdsConsentManager: NSObject { // debugSettings.geography = UMPDebugGeography.EEA parameters.debugSettings = debugSettings + // [START gather_consent] // Requesting an update to consent information should be called on every app launch. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) { requestConsentError in @@ -64,12 +67,15 @@ class GoogleMobileAdsConsentManager: NSObject { } } } + // [END gather_consent] } /// Helper method to call the UMP SDK method to present the privacy options form. @MainActor func presentPrivacyOptionsForm(from viewController: UIViewController? = nil) async throws { + // [START present_privacy_options_form] try await UMPConsentForm.presentPrivacyOptionsForm(from: viewController) + // [END present_privacy_options_form] } } diff --git a/Swift/admob/BannerExample/BannerExample/ViewController.swift b/Swift/admob/BannerExample/BannerExample/ViewController.swift index 71c36eaf..ede923fc 100644 --- a/Swift/admob/BannerExample/BannerExample/ViewController.swift +++ b/Swift/admob/BannerExample/BannerExample/ViewController.swift @@ -34,6 +34,7 @@ class ViewController: UIViewController, GADBannerViewDelegate { bannerView.rootViewController = self bannerView.delegate = self + // [START can_request_ads] GoogleMobileAdsConsentManager.shared.gatherConsent(from: self) { [weak self] consentError in guard let self else { return } @@ -45,15 +46,20 @@ class ViewController: UIViewController, GADBannerViewDelegate { if GoogleMobileAdsConsentManager.shared.canRequestAds { self.startGoogleMobileAdsSDK() } + // [START_EXCLUDE] + // [START add_privacy_options] self.privacySettingsButton.isEnabled = GoogleMobileAdsConsentManager.shared.isPrivacyOptionsRequired + // [END add_privacy_options] + // [END_EXCLUDE] } // This sample attempts to load ads using consent obtained in the previous session. if GoogleMobileAdsConsentManager.shared.canRequestAds { startGoogleMobileAdsSDK() } + // [END can_request_ads] } override func viewDidAppear(_ animated: Bool) { @@ -108,6 +114,7 @@ class ViewController: UIViewController, GADBannerViewDelegate { } } + // [START request_ads] private func startGoogleMobileAdsSDK() { DispatchQueue.main.async { guard !self.isMobileAdsStartCalled else { return } @@ -122,6 +129,7 @@ class ViewController: UIViewController, GADBannerViewDelegate { } } } + // [END request_ads] func loadBannerAd() { let viewWidth = view.frame.inset(by: view.safeAreaInsets).width