Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal change #484

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading