-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UMP SDK integration to Ad Manager Objective-C & Swift samples
PiperOrigin-RevId: 553259704
- Loading branch information
1 parent
3ff3922
commit 39a970e
Showing
16 changed files
with
483 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
Objective-C/admanager/AdManagerBannerExample/AdManagerBannerExample/AppDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
Objective-C/admanager/AdManagerBannerExample/AdManagerBannerExample/AppDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...C/admanager/AdManagerBannerExample/AdManagerBannerExample/GoogleMobileAdsConsentManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright (C) 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/// The Google Mobile Ads SDK provides the User Messaging Platform (Google's | ||
/// IAB Certified consent management platform) as one solution to capture | ||
/// consent for users in GDPR impacted countries. This is an example and | ||
/// you can choose another consent management platform to capture consent. | ||
@interface GoogleMobileAdsConsentManager : NSObject | ||
|
||
@property(class, atomic, readonly, strong, nonnull) GoogleMobileAdsConsentManager *sharedInstance; | ||
@property(nonatomic, readonly) BOOL canRequestAds; | ||
@property(nonatomic, readonly) BOOL isPrivacyOptionsRequired; | ||
|
||
/// Helper method to call the UMP SDK methods to request consent information and load/present a | ||
/// consent form if necessary. | ||
- (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)viewController | ||
consentGatheringComplete: | ||
(void (^)(NSError *_Nullable error))completionHandler; | ||
|
||
/// Helper method to call the UMP SDK method to present the privacy options form. | ||
- (void)presentPrivacyOptionsFormFromViewController:(UIViewController *)viewController | ||
completionHandler: | ||
(void (^)(NSError *_Nullable error))completionHandler; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
80 changes: 80 additions & 0 deletions
80
...C/admanager/AdManagerBannerExample/AdManagerBannerExample/GoogleMobileAdsConsentManager.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// Copyright (C) 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import "GoogleMobileAdsConsentManager.h" | ||
|
||
#import <GoogleMobileAds/GoogleMobileAds.h> | ||
#import <UserMessagingPlatform/UserMessagingPlatform.h> | ||
|
||
|
||
@implementation GoogleMobileAdsConsentManager | ||
|
||
+ (instancetype)sharedInstance { | ||
static GoogleMobileAdsConsentManager *shared; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
shared = [[GoogleMobileAdsConsentManager alloc] init]; | ||
}); | ||
return shared; | ||
} | ||
|
||
- (BOOL)canRequestAds { | ||
return UMPConsentInformation.sharedInstance.canRequestAds; | ||
} | ||
|
||
- (BOOL)isPrivacyOptionsRequired { | ||
return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == | ||
UMPPrivacyOptionsRequirementStatusRequired; | ||
} | ||
|
||
- (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)viewController | ||
consentGatheringComplete: | ||
(void (^)(NSError *_Nullable))consentGatheringComplete { | ||
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; | ||
|
||
// For testing purposes, you can force a UMPDebugGeography of EEA or not EEA. | ||
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init]; | ||
// debugSettings.geography = UMPDebugGeographyEEA; | ||
parameters.debugSettings = debugSettings; | ||
|
||
// Requesting an update to consent information should be called on every app launch. | ||
[UMPConsentInformation.sharedInstance | ||
requestConsentInfoUpdateWithParameters:parameters | ||
completionHandler:^(NSError *_Nullable requestConsentError) { | ||
if (requestConsentError) { | ||
consentGatheringComplete(requestConsentError); | ||
} else { | ||
[UMPConsentForm | ||
loadAndPresentIfRequiredFromViewController:viewController | ||
completionHandler:^( | ||
NSError | ||
*_Nullable loadAndPresentError) { | ||
// Consent has been gathered. | ||
consentGatheringComplete( | ||
loadAndPresentError); | ||
}]; | ||
} | ||
}]; | ||
} | ||
|
||
- (void)presentPrivacyOptionsFormFromViewController:(UIViewController *)viewController | ||
completionHandler: | ||
(void (^)(NSError *_Nullable))completionHandler { | ||
[UMPConsentForm presentPrivacyOptionsFormFromViewController:viewController | ||
completionHandler:completionHandler]; | ||
} | ||
|
||
@end |
16 changes: 15 additions & 1 deletion
16
Objective-C/admanager/AdManagerBannerExample/AdManagerBannerExample/ViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.