Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 696289360
  • Loading branch information
Justin Malandruccolo authored and copybara-github committed Nov 13, 2024
1 parent 15b219f commit 043de5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -79,4 +84,5 @@ class GoogleMobileAdsConsentManager: NSObject {
// Initialize the Google Mobile Ads SDK.
GADMobileAds.sharedInstance().start()
}
// [END request_ads]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
Expand Down

0 comments on commit 043de5a

Please sign in to comment.