Skip to content

Commit

Permalink
Added UMP SDK integration to Ad Manager Objective-C & Swift samples
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 553259704
  • Loading branch information
Justin Malandruccolo authored and maddevrelgithubbot committed Aug 4, 2023
1 parent 3ff3922 commit 39a970e
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
50931E662151A9C60031BE3E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50931E5F2151A9C60031BE3E /* Images.xcassets */; };
50931E682151A9C60031BE3E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50931E622151A9C60031BE3E /* ViewController.m */; };
50931E692151A9C60031BE3E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 50931E632151A9C60031BE3E /* main.m */; };
A863EB632A7B08D800FBEB64 /* GoogleMobileAdsConsentManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A863EB622A7B08D800FBEB64 /* GoogleMobileAdsConsentManager.m */; };
EFE9E28025DF3988002F7C5A /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EFE9E27F25DF3988002F7C5A /* StoreKit.framework */; };
EFE9E28225DF3DD1002F7C5A /* GoogleAppMeasurement.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EFE9E27C25DF3876002F7C5A /* GoogleAppMeasurement.xcframework */; };
EFE9E28325DF3DD6002F7C5A /* GoogleMobileAds.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EFE9E27A25DF3860002F7C5A /* GoogleMobileAds.xcframework */; };
Expand All @@ -26,6 +27,8 @@
50931E612151A9C60031BE3E /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
50931E622151A9C60031BE3E /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
50931E632151A9C60031BE3E /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
A863EB612A7B08D800FBEB64 /* GoogleMobileAdsConsentManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GoogleMobileAdsConsentManager.h; sourceTree = "<group>"; };
A863EB622A7B08D800FBEB64 /* GoogleMobileAdsConsentManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GoogleMobileAdsConsentManager.m; sourceTree = "<group>"; };
CF12E27E19A6C783001EB38A /* AdManagerBannerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AdManagerBannerExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
EFE9E27A25DF3860002F7C5A /* GoogleMobileAds.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = GoogleMobileAds.xcframework; path = "Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework/GoogleMobileAds.xcframework"; sourceTree = "<group>"; };
EFE9E27C25DF3876002F7C5A /* GoogleAppMeasurement.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = GoogleAppMeasurement.xcframework; path = Pods/GoogleAppMeasurement/Frameworks/GoogleAppMeasurement.xcframework; sourceTree = "<group>"; };
Expand All @@ -51,6 +54,8 @@
children = (
50931E5B2151A9C60031BE3E /* AppDelegate.h */,
50931E5C2151A9C60031BE3E /* AppDelegate.m */,
A863EB612A7B08D800FBEB64 /* GoogleMobileAdsConsentManager.h */,
A863EB622A7B08D800FBEB64 /* GoogleMobileAdsConsentManager.m */,
50931E5D2151A9C60031BE3E /* Main.storyboard */,
50931E5F2151A9C60031BE3E /* Images.xcassets */,
50931E602151A9C60031BE3E /* Info.plist */,
Expand Down Expand Up @@ -166,6 +171,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A863EB632A7B08D800FBEB64 /* GoogleMobileAdsConsentManager.m in Sources */,
50931E682151A9C60031BE3E /* ViewController.m in Sources */,
50931E692151A9C60031BE3E /* main.m in Sources */,
50931E642151A9C60031BE3E /* AppDelegate.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// Copyright (c) 2014 Google. All rights reserved.
//
// Copyright (C) 2014 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>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// Copyright (c) 2014 Google. All rights reserved.
//
// Copyright (C) 2014 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 "AppDelegate.h"
#import <GoogleMobileAds/GoogleMobileAds.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina3_5" orientation="portrait" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="I2k-Tk-Ql0">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="6Vs-oQ-PZA">
<objects>
<navigationController id="I2k-Tk-Ql0" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="mvh-jd-d5M">
<rect key="frame" x="0.0" y="59" width="393" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="BT4-IE-4oK"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="79R-RW-eZH" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1355" y="296"/>
</scene>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
Expand All @@ -16,11 +32,11 @@
<viewControllerLayoutGuide type="bottom" id="LF1-Ug-RAX"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jPL-30-0SK" customClass="GAMBannerView">
<rect key="frame" x="0.0" y="430" width="320" height="50"/>
<rect key="frame" x="36.666666666666657" y="768" width="320" height="50"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="ZaG-Ct-7iz"/>
Expand All @@ -34,13 +50,21 @@
<constraint firstItem="jPL-30-0SK" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="TDu-IU-gjl"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="lTn-F8-vJq">
<barButtonItem key="rightBarButtonItem" enabled="NO" title="Privacy Settings" id="Yww-jA-bXG">
<connections>
<action selector="privacySettingsTapped:" destination="BYZ-38-t0r" id="GiJ-B4-wKI"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="bannerView" destination="jPL-30-0SK" id="rUl-2d-laY"/>
<outlet property="privacySettingsButton" destination="Yww-jA-bXG" id="WSz-kj-LSr"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="171.01449275362319" y="264.50892857142856"/>
<point key="canvasLocation" x="-160" y="296"/>
</scene>
</scenes>
</document>
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
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// Copyright (c) 2014 Google. All rights reserved.
//
// Copyright (C) 2014 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>

Expand Down
Loading

0 comments on commit 39a970e

Please sign in to comment.