Skip to content

Commit

Permalink
Add includecode comments for UMP SDK integration
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 686987300
  • Loading branch information
Interactive Media Ads Developer Relations authored and IMA Developer Relations committed Oct 17, 2024
1 parent 26c1b47 commit b36319e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Objective-C/UmpExample/UmpExample/ConsentManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ - (BOOL)canRequestAds {
return UMPConsentInformation.sharedInstance.canRequestAds;
}

// [START is_privacy_options_required]
- (BOOL)areGDPRConsentMessagesRequired {
return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
UMPPrivacyOptionsRequirementStatusRequired;
}
// [END is_privacy_options_required]

- (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)viewController
consentGatheringComplete:
Expand All @@ -51,6 +53,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
Expand All @@ -69,13 +72,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
8 changes: 8 additions & 0 deletions Objective-C/UmpExample/UmpExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ - (void)viewDidLoad {
self.playButton.layer.zPosition = MAXFLOAT;

__weak __typeof__(self) weakSelf = self;
// [START can_request_ads]
[ConsentManager.sharedInstance
gatherConsentFromConsentPresentationViewController:self
consentGatheringComplete:^(NSError *_Nullable consentError) {
Expand All @@ -100,11 +101,15 @@ - (void)viewDidLoad {
return;
}

// [START_EXCLUDE]
// [START add_privacy_options]
// Set up the privacy options button to show the UMP privacy form.
// Check ConsentInformation.getPrivacyOptionsRequirementStatus
// to see the button should be shown or hidden.
strongSelf.privacySettingsButton.hidden =
!ConsentManager.sharedInstance.areGDPRConsentMessagesRequired;
// [END add_privacy_options]
// [END_EXCLUDE]

if (ConsentManager.sharedInstance.canRequestAds) {
[strongSelf setupAdsLoader];
Expand All @@ -115,6 +120,7 @@ - (void)viewDidLoad {
if (ConsentManager.sharedInstance.canRequestAds) {
[self setupAdsLoader];
}
// [START can_request_ads]

[self setUpContentPlayer];
}
Expand Down Expand Up @@ -148,10 +154,12 @@ - (void)setUpContentPlayer {

#pragma mark SDK Setup

// [START request_ads]
- (void)setupAdsLoader {
self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:nil];
self.adsLoader.delegate = self;
}
// [END request_ads]

- (void)requestAds {
// Create an ad display container for ad rendering.
Expand Down
6 changes: 6 additions & 0 deletions Swift/UmpExample/UmpExample/ConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class ConsentManager: 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.
Expand All @@ -47,6 +49,7 @@ class ConsentManager: 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 @@ -61,13 +64,16 @@ class ConsentManager: NSObject {
consentGatheringComplete(loadAndPresentError)
}
}
// [END gather_consent]
}

/// Helper method to call the UMP SDK method to present the privacy options form.
func presentPrivacyOptionsForm(
from viewController: UIViewController, completionHandler: @escaping (Error?) -> Void
) {
// [START present_privacy_options_form]
UMPConsentForm.presentPrivacyOptionsForm(
from: viewController, completionHandler: completionHandler)
// [END present_privacy_options_form]
}
}
8 changes: 8 additions & 0 deletions Swift/UmpExample/UmpExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAAdsManagerDeleg

playButton.layer.zPosition = CGFloat.greatestFiniteMagnitude

// [START can_request_ads]
ConsentManager.shared.gatherConsent(from: self) { [weak self] consentError in
guard let self else { return }

Expand All @@ -49,9 +50,14 @@ class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAAdsManagerDeleg
// consent obtained in the previous session.
print("Error: \(consentError.localizedDescription)")
}
// [START_EXCLUDE]

// [START add_privacy_options]
self.privacySettingsButton.isEnabled = ConsentManager.shared.isPrivacyOptionsRequired
// [END add_privacy_options]
// [END_EXCLUDE]
}
// [END can_request_ads]

setUpContentPlayer()
adsLoader.delegate = self
Expand Down Expand Up @@ -120,6 +126,7 @@ class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAAdsManagerDeleg

// MARK: IMA integration methods

// [START request_ads]
private func requestAds() {
// Create ad display container for ad rendering.
let adDisplayContainer = IMAAdDisplayContainer(
Expand All @@ -133,6 +140,7 @@ class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAAdsManagerDeleg

adsLoader.requestAds(with: request)
}
// [END request_ads]

// MARK: - IMAAdsLoaderDelegate

Expand Down

0 comments on commit b36319e

Please sign in to comment.