diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift index 139e2da2..648a38ed 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift @@ -46,6 +46,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 @@ -63,13 +64,17 @@ class GoogleMobileAdsConsentManager: NSObject { } } } + // [END gather_consent] } /// Helper method to call the UMP SDK method to present the privacy options form. @MainActor func presentPrivacyOptionsForm() async throws { + // [START present_privacy_options_form] try await UMPConsentForm.presentPrivacyOptionsForm(from: nil) + // [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 } @@ -79,4 +84,5 @@ 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 ff1c8982..1cb74915 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuView.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuView.swift @@ -43,21 +43,27 @@ struct MenuView: View { } } .onAppear { + // [START can_request_ads] GoogleMobileAdsConsentManager.shared.gatherConsent { consentError in if let consentError { // Consent gathering failed. print("Error: \(consentError.localizedDescription)") } + // 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 - - GoogleMobileAdsConsentManager.shared.startGoogleMobileAdsSDK() + // [END_EXCLUDE] } // This sample attempts to load ads using consent obtained in the previous session. GoogleMobileAdsConsentManager.shared.startGoogleMobileAdsSDK() + // [END can_request_ads] } } }