Skip to content

Commit

Permalink
Added UMP SDK integration to Adaptive Banner Objective-C & Swift samples
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 555655077
  • Loading branch information
Justin Malandruccolo authored and maddevrelgithubbot committed Aug 10, 2023
1 parent a0a4597 commit ea0aea5
Show file tree
Hide file tree
Showing 26 changed files with 849 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
A8369D7B2A84216100F125DE /* GoogleMobileAdsConsentManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A8369D792A84216100F125DE /* GoogleMobileAdsConsentManager.m */; };
CF86EE1D19787E6B00411520 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = CF86EE1C19787E6B00411520 /* main.m */; };
CF86EE2019787E6B00411520 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = CF86EE1F19787E6B00411520 /* AppDelegate.m */; };
CF86EE2319787E6B00411520 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CF86EE2219787E6B00411520 /* ViewController.m */; };
Expand All @@ -15,6 +16,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
A8369D792A84216100F125DE /* GoogleMobileAdsConsentManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GoogleMobileAdsConsentManager.m; sourceTree = "<group>"; };
A8369D7A2A84216100F125DE /* GoogleMobileAdsConsentManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GoogleMobileAdsConsentManager.h; sourceTree = "<group>"; };
CF86EE1719787E6B00411520 /* AdaptiveBannerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AdaptiveBannerExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
CF86EE1B19787E6B00411520 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CF86EE1C19787E6B00411520 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand All @@ -37,11 +40,19 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
76596DC8E8109CB3E49DD466 /* Pods */ = {
isa = PBXGroup;
children = (
);
path = Pods;
sourceTree = "<group>";
};
CF86EE0E19787E6B00411520 = {
isa = PBXGroup;
children = (
CF86EE1919787E6B00411520 /* AdaptiveBannerExample */,
CF86EE1819787E6B00411520 /* Products */,
76596DC8E8109CB3E49DD466 /* Pods */,
);
sourceTree = "<group>";
};
Expand All @@ -58,6 +69,8 @@
children = (
CF86EE1E19787E6B00411520 /* AppDelegate.h */,
CF86EE1F19787E6B00411520 /* AppDelegate.m */,
A8369D7A2A84216100F125DE /* GoogleMobileAdsConsentManager.h */,
A8369D792A84216100F125DE /* GoogleMobileAdsConsentManager.m */,
CF86EE2119787E6B00411520 /* ViewController.h */,
CF86EE2219787E6B00411520 /* ViewController.m */,
CF86EE2419787E6B00411520 /* Main.storyboard */,
Expand Down Expand Up @@ -146,6 +159,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A8369D7B2A84216100F125DE /* GoogleMobileAdsConsentManager.m in Sources */,
CF86EE2319787E6B00411520 /* ViewController.m in Sources */,
CF86EE2019787E6B00411520 /* AppDelegate.m in Sources */,
CF86EE1D19787E6B00411520 /* main.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2019 Google, Inc.
// Copyright (C) 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2019 Google, Inc.
// Copyright (C) 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
//

#import "AppDelegate.h"
#import <GoogleMobileAds/GoogleMobileAds.h>

@interface AppDelegate ()

Expand All @@ -25,12 +24,6 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the iOS simulator as a test device (this is default behavior but included for
// demonstration purposes).
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ GADSimulatorID ];

// Initialize Google Mobile Ads SDK
[GADMobileAds.sharedInstance startWithCompletionHandler:nil];
return YES;
}

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="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22113.1" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="hrC-kg-0cx">
<device id="retina5_9" orientation="portrait" appearance="light"/>
<dependencies>
<deployment version="2304" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="C4n-XQ-wRB">
<objects>
<navigationController id="hrC-kg-0cx" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="FPg-sG-Arc">
<rect key="frame" x="0.0" y="50" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="Uds-uW-h0Q"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="uSn-6A-8ax" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1388" y="-1360"/>
</scene>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
Expand All @@ -20,7 +36,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Adaptive Banner Example" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ChV-Lb-5si">
<rect key="frame" x="55.666666666666657" y="94" width="264" height="29"/>
<rect key="frame" x="55.666666666666657" y="144" width="264" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand All @@ -29,7 +45,7 @@
<rect key="frame" x="27.666666666666657" y="728" width="320" height="50"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5SE-ge-dYq">
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5SE-ge-dYq">
<rect key="frame" x="159.66666666666666" y="441" width="56" height="30"/>
<state key="normal" title="Load Ad"/>
<connections>
Expand All @@ -43,7 +59,7 @@
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Reservation ad unit" textAlignment="natural" lineBreakMode="characterWrap" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="9" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jKS-TQ-SW8">
<rect key="frame" x="114.66666666666667" y="400.66666666666669" width="145.66666666666663" height="20.333333333333314"/>
<rect key="frame" x="114.66666666666669" y="400.66666666666669" width="146" height="20.333333333333314"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand All @@ -64,11 +80,20 @@
</constraints>
</view>
<toolbarItems/>
<navigationItem key="navigationItem" id="OeE-zL-ruC">
<barButtonItem key="rightBarButtonItem" enabled="NO" title="Privacy Settings" id="D2V-uK-vBr">
<connections>
<action selector="privacySettingsTapped:" destination="BYZ-38-t0r" id="X1t-s1-ism"/>
</connections>
</barButtonItem>
</navigationItem>
<nil key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="bannerView" destination="b5b-Tm-bLe" id="2XW-6t-gNF"/>
<outlet property="iuLabel" destination="jKS-TQ-SW8" id="Qsn-jV-Q6a"/>
<outlet property="iuSwitch" destination="2jT-3O-hP3" id="g0e-GZ-nqR"/>
<outlet property="loadAdButton" destination="5SE-ge-dYq" id="9bR-dZ-Wnk"/>
<outlet property="privacySettingsButton" destination="D2V-uK-vBr" id="OcZ-AT-gNS"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down
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,5 +1,5 @@
//
// Copyright (C) 2019 Google, Inc.
// Copyright (C) 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,8 @@
@interface ViewController : UIViewController

@property(nonatomic, weak) IBOutlet GAMBannerView *bannerView;
@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;
@property(weak, nonatomic) IBOutlet UIButton *loadAdButton;
@property(weak, nonatomic) IBOutlet UISwitch *iuSwitch;
@property(weak, nonatomic) IBOutlet UILabel *iuLabel;

Expand Down
Loading

0 comments on commit ea0aea5

Please sign in to comment.