diff --git a/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m b/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m index dc9611f6..605326f0 100644 --- a/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m +++ b/Objective-C/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.m @@ -52,26 +52,35 @@ - (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)v // debugSettings.geography = UMPDebugGeographyEEA; parameters.debugSettings = debugSettings; - // [START gather_consent] + // [START request_consent_info_update] // Requesting an update to consent information should be called on every app launch. [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError *_Nullable requestConsentError) { + // [START_EXCLUDE] if (requestConsentError) { consentGatheringComplete(requestConsentError); } else { - [UMPConsentForm - loadAndPresentIfRequiredFromViewController:viewController - completionHandler:^( - NSError - *_Nullable loadAndPresentError) { - // Consent has been gathered. - consentGatheringComplete( - loadAndPresentError); - }]; + [self loadAndPresentIfRequiredFromViewController:viewController + completionHandler:consentGatheringComplete]; } + // [END_EXCLUDE] }]; - // [END gather_consent] + // [END request_consent_info_update] +} + +- (void)loadAndPresentIfRequiredFromViewController:(UIViewController *)viewController + completionHandler:(void (^)(NSError *_Nullable))completionHandler { + // [START load_and_present_consent_form] + [UMPConsentForm + loadAndPresentIfRequiredFromViewController:viewController + completionHandler:^(NSError *_Nullable loadAndPresentError) { + // Consent gathering process is complete. + // [START_EXCLUDE silent] + completionHandler(loadAndPresentError); + // [END_EXCLUDE] + }]; + // [END load_and_present_consent_form] } - (void)presentPrivacyOptionsFormFromViewController:(UIViewController *)viewController diff --git a/Objective-C/admob/BannerExample/BannerExample/ViewController.m b/Objective-C/admob/BannerExample/BannerExample/ViewController.m index 8d634bf8..72a6d2d9 100644 --- a/Objective-C/admob/BannerExample/BannerExample/ViewController.m +++ b/Objective-C/admob/BannerExample/BannerExample/ViewController.m @@ -85,7 +85,6 @@ - (void)viewDidLoad { self.bannerView.delegate = self; __weak __typeof__(self) weakSelf = self; - // [START can_request_ads] [GoogleMobileAdsConsentManager.sharedInstance gatherConsentFromConsentPresentationViewController:self consentGatheringComplete:^(NSError *_Nullable consentError) { @@ -102,21 +101,16 @@ - (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 { @@ -139,7 +133,6 @@ - (void)viewWillTransitionToSize:(CGSize)size completion:nil]; } -// [START request_ads] - (void)startGoogleMobileAdsSDK { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -148,7 +141,6 @@ - (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 7b43d383..34141bc3 100644 --- a/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift @@ -30,11 +30,9 @@ 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. @@ -49,25 +47,29 @@ class GoogleMobileAdsConsentManager: NSObject { // debugSettings.geography = UMPDebugGeography.EEA parameters.debugSettings = debugSettings - // [START gather_consent] + // [START request_consent_info_update] // Requesting an update to consent information should be called on every app launch. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) { requestConsentError in + // [START_EXCLUDE] guard requestConsentError == nil else { return consentGatheringComplete(requestConsentError) } Task { @MainActor in do { + // [START load_and_present_consent_form] try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) + // [END load_and_present_consent_form] // Consent has been gathered. consentGatheringComplete(nil) } catch { consentGatheringComplete(error) } } + // [END_EXCLUDE] } - // [END gather_consent] + // [END request_consent_info_update] } /// Helper method to call the UMP SDK method to present the privacy options form. diff --git a/Swift/admob/BannerExample/BannerExample/ViewController.swift b/Swift/admob/BannerExample/BannerExample/ViewController.swift index ede923fc..71c36eaf 100644 --- a/Swift/admob/BannerExample/BannerExample/ViewController.swift +++ b/Swift/admob/BannerExample/BannerExample/ViewController.swift @@ -34,7 +34,6 @@ 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 } @@ -46,20 +45,15 @@ 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) { @@ -114,7 +108,6 @@ class ViewController: UIViewController, GADBannerViewDelegate { } } - // [START request_ads] private func startGoogleMobileAdsSDK() { DispatchQueue.main.async { guard !self.isMobileAdsStartCalled else { return } @@ -129,7 +122,6 @@ class ViewController: UIViewController, GADBannerViewDelegate { } } } - // [END request_ads] func loadBannerAd() { let viewWidth = view.frame.inset(by: view.safeAreaInsets).width diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift index 648a38ed..ca2180f9 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift @@ -46,25 +46,29 @@ class GoogleMobileAdsConsentManager: NSObject { // debugSettings.geography = UMPDebugGeography.EEA parameters.debugSettings = debugSettings - // [START gather_consent] + // [START request_consent_info_update] // Requesting an update to consent information should be called on every app launch. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) { requestConsentError in + // [START_EXCLUDE] guard requestConsentError == nil else { return consentGatheringComplete(requestConsentError) } Task { @MainActor in do { + // [START load_and_present_consent_form] try await UMPConsentForm.loadAndPresentIfRequired(from: nil) + // [END load_and_present_consent_form] // Consent has been gathered. consentGatheringComplete(nil) } catch { consentGatheringComplete(error) } } + // [END_EXCLUDE] } - // [END gather_consent] + // [END request_consent_info_update] } /// Helper method to call the UMP SDK method to present the privacy options form. @@ -74,7 +78,6 @@ class GoogleMobileAdsConsentManager: NSObject { // [END present_privacy_options_form] } - // [START request_ads] /// Method to initialize the Google Mobile Ads SDK. The SDK should only be initialized once. func startGoogleMobileAdsSDK() { guard canRequestAds, !isMobileAdsStartCalled else { return } @@ -84,5 +87,4 @@ class GoogleMobileAdsConsentManager: NSObject { // Initialize the Google Mobile Ads SDK. GADMobileAds.sharedInstance().start() } - // [END request_ads] } diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuView.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuView.swift index 1cb74915..2429d14e 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuView.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuView.swift @@ -43,7 +43,6 @@ struct MenuView: View { } } .onAppear { - // [START can_request_ads] GoogleMobileAdsConsentManager.shared.gatherConsent { consentError in if let consentError { // Consent gathering failed. @@ -53,17 +52,14 @@ struct MenuView: View { // Check if you can request ads in `startGoogleMobileAdsSDK` before initializing the // Google Mobile Ads SDK. GoogleMobileAdsConsentManager.shared.startGoogleMobileAdsSDK() - // [START_EXCLUDE] // Update the state of the menu items and privacy options button. isMenuItemDisabled = !GoogleMobileAdsConsentManager.shared.canRequestAds isPrivacyOptionsButtonDisabled = !GoogleMobileAdsConsentManager.shared .isPrivacyOptionsRequired - // [END_EXCLUDE] } // This sample attempts to load ads using consent obtained in the previous session. GoogleMobileAdsConsentManager.shared.startGoogleMobileAdsSDK() - // [END can_request_ads] } } }