Skip to content

Commit 3de4e13

Browse files
malandr2copybara-github
authored andcommitted
Add region tags for native ad options snippets
PiperOrigin-RevId: 797278401
1 parent e9135c6 commit 3de4e13

File tree

5 files changed

+324
-1
lines changed

5 files changed

+324
-1
lines changed

Objective-C/advanced/APIDemo/APIDemo.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
50DC0CFC212F1C4000424CC7 /* GAMAppEventsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DC0CF6212F1C3F00424CC7 /* GAMAppEventsViewController.m */; };
2525
50DC0CFD212F1C4000424CC7 /* GAMCustomTargetingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DC0CF7212F1C3F00424CC7 /* GAMCustomTargetingViewController.m */; };
2626
50DC0CFE212F1C4000424CC7 /* GAMPPIDViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DC0CF8212F1C4000424CC7 /* GAMPPIDViewController.m */; };
27+
A8265F742E4F8AE000A9C150 /* BannerSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = A8265F722E4F8AE000A9C150 /* BannerSnippets.m */; };
28+
A8265F752E4F8AE000A9C150 /* ResponseInfoSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = A8265F732E4F8AE000A9C150 /* ResponseInfoSnippets.m */; };
29+
A8265F772E4F8AF600A9C150 /* NativeAdOptionsSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = A8265F762E4F8AEF00A9C150 /* NativeAdOptionsSnippets.m */; };
2730
A846F1C32E2584AD00F96E49 /* RewardedAdSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = A846F1C22E2584A800F96E49 /* RewardedAdSnippets.m */; };
2831
A86568AD2E254DD800D360C3 /* ATTSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = A86568AC2E254DD300D360C3 /* ATTSnippets.m */; };
2932
A8B6503A2DD63FA500AE1D3F /* RequestConfigurationSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = A8B650392DD63FA500AE1D3F /* RequestConfigurationSnippets.m */; };
@@ -68,6 +71,9 @@
6871
50DC0CF6212F1C3F00424CC7 /* GAMAppEventsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GAMAppEventsViewController.m; sourceTree = "<group>"; };
6972
50DC0CF7212F1C3F00424CC7 /* GAMCustomTargetingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GAMCustomTargetingViewController.m; sourceTree = "<group>"; };
7073
50DC0CF8212F1C4000424CC7 /* GAMPPIDViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GAMPPIDViewController.m; sourceTree = "<group>"; };
74+
A8265F722E4F8AE000A9C150 /* BannerSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BannerSnippets.m; sourceTree = "<group>"; };
75+
A8265F732E4F8AE000A9C150 /* ResponseInfoSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ResponseInfoSnippets.m; sourceTree = "<group>"; };
76+
A8265F762E4F8AEF00A9C150 /* NativeAdOptionsSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NativeAdOptionsSnippets.m; sourceTree = "<group>"; };
7177
A846F1C22E2584A800F96E49 /* RewardedAdSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RewardedAdSnippets.m; sourceTree = "<group>"; };
7278
A86568AC2E254DD300D360C3 /* ATTSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ATTSnippets.m; sourceTree = "<group>"; };
7379
A8B650392DD63FA500AE1D3F /* RequestConfigurationSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RequestConfigurationSnippets.m; sourceTree = "<group>"; };
@@ -179,7 +185,10 @@
179185
isa = PBXGroup;
180186
children = (
181187
A86568AC2E254DD300D360C3 /* ATTSnippets.m */,
188+
A8265F722E4F8AE000A9C150 /* BannerSnippets.m */,
189+
A8265F762E4F8AEF00A9C150 /* NativeAdOptionsSnippets.m */,
182190
A8B650392DD63FA500AE1D3F /* RequestConfigurationSnippets.m */,
191+
A8265F732E4F8AE000A9C150 /* ResponseInfoSnippets.m */,
183192
A846F1C22E2584A800F96E49 /* RewardedAdSnippets.m */,
184193
);
185194
path = Snippets;
@@ -290,6 +299,9 @@
290299
4A96E79D1B862E0200031470 /* AdMobAdTargetingTableViewController.m in Sources */,
291300
50DC0CFB212F1C4000424CC7 /* GAMMultipleAdSizesViewController.m in Sources */,
292301
EF98F6062BD948C900FDCA41 /* CollapsibleBannerViewController.m in Sources */,
302+
A8265F772E4F8AF600A9C150 /* NativeAdOptionsSnippets.m in Sources */,
303+
A8265F742E4F8AE000A9C150 /* BannerSnippets.m in Sources */,
304+
A8265F752E4F8AE000A9C150 /* ResponseInfoSnippets.m in Sources */,
293305
50DC0CFA212F1C4000424CC7 /* GAMFluidAdSizeViewController.m in Sources */,
294306
A8B6503A2DD63FA500AE1D3F /* RequestConfigurationSnippets.m in Sources */,
295307
AEE8DAA5201BDCA9008792E6 /* CustomControlsView.m in Sources */,
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
//
2+
// Copyright (C) 2025 Google, Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import <GoogleMobileAds/GoogleMobileAds.h>
18+
#import <UIKit/UIKit.h>
19+
20+
NS_ASSUME_NONNULL_BEGIN
21+
22+
// Replace this ad unit ID with your own ad unit ID.
23+
static NSString *const nativeAdUnitID = @"ca-app-pub-3940256099942544/3986624511";
24+
25+
@interface NativeAdOptionsSnippets : UIViewController <GADNativeAdDelegate>
26+
// The ad loader.
27+
@property(nonatomic, strong) GADAdLoader *adLoader;
28+
@end
29+
30+
@implementation NativeAdOptionsSnippets
31+
32+
- (void)setMediaAspectRatio {
33+
// [START set_media_aspect_ratio]
34+
GADNativeAdMediaAdLoaderOptions *nativeOptions = [[GADNativeAdMediaAdLoaderOptions alloc] init];
35+
nativeOptions.mediaAspectRatio = GADMediaAspectRatioAny;
36+
37+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:nativeAdUnitID
38+
rootViewController:self
39+
adTypes:@[ GADAdLoaderAdTypeNative ]
40+
options:@[ nativeOptions ]];
41+
// [END set_media_aspect_ratio]
42+
}
43+
44+
- (void)setDisableImageLoading {
45+
// [START set_disable_image_loading]
46+
GADNativeAdImageAdLoaderOptions *nativeOptions = [[GADNativeAdImageAdLoaderOptions alloc] init];
47+
nativeOptions.disableImageLoading = YES;
48+
49+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:nativeAdUnitID
50+
rootViewController:self
51+
adTypes:@[ GADAdLoaderAdTypeNative ]
52+
options:@[ nativeOptions ]];
53+
// [END set_disable_image_loading]
54+
}
55+
56+
- (void)setRequestMultipleImages {
57+
// [START set_request_multiple_images]
58+
GADNativeAdImageAdLoaderOptions *nativeOptions = [[GADNativeAdImageAdLoaderOptions alloc] init];
59+
nativeOptions.shouldRequestMultipleImages = YES;
60+
61+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:nativeAdUnitID
62+
rootViewController:self
63+
adTypes:@[ GADAdLoaderAdTypeNative ]
64+
options:@[ nativeOptions ]];
65+
// [END set_request_multiple_images]
66+
}
67+
68+
- (void)setAdChoicesPosition {
69+
// [START set_ad_choices_position]
70+
GADNativeAdViewAdOptions *nativeOptions = [[GADNativeAdViewAdOptions alloc] init];
71+
nativeOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner;
72+
73+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:nativeAdUnitID
74+
rootViewController:self
75+
adTypes:@[ GADAdLoaderAdTypeNative ]
76+
options:@[ nativeOptions ]];
77+
// [END set_ad_choices_position]
78+
}
79+
80+
// [START create_ad_choices_view]
81+
- (void)createAdChoicesViewWithNativeAdView:(GADNativeAdView *)nativeAdView {
82+
// Define a custom position for the AdChoices icon.
83+
CGRect customRect = CGRectMake(100, 100, 15, 15);
84+
GADAdChoicesView *customAdChoicesView = [[GADAdChoicesView alloc] initWithFrame:customRect];
85+
[nativeAdView addSubview:customAdChoicesView];
86+
nativeAdView.adChoicesView = customAdChoicesView;
87+
}
88+
// [END create_ad_choices_view]
89+
90+
- (void)setMuted {
91+
// [START set_muted]
92+
GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
93+
videoOptions.startMuted = NO;
94+
95+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:nativeAdUnitID
96+
rootViewController:self
97+
adTypes:@[ GADAdLoaderAdTypeNative ]
98+
options:@[ videoOptions ]];
99+
// [END set_muted]
100+
}
101+
102+
- (void)setRequestCustomPlaybackControls {
103+
// [START set_request_custom_playback_controls]
104+
GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
105+
videoOptions.customControlsRequested = YES;
106+
107+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:nativeAdUnitID
108+
rootViewController:self
109+
adTypes:@[ GADAdLoaderAdTypeNative ]
110+
options:@[ videoOptions ]];
111+
// [END set_request_custom_playback_controls]
112+
}
113+
114+
// [START check_custom_controls_enabled]
115+
- (BOOL)checkCustomControlsEnabledWithNativeAd:(GADNativeAd *)nativeAd {
116+
GADVideoController *videoController = nativeAd.mediaContent.videoController;
117+
return videoController.customControlsEnabled;
118+
}
119+
// [END check_custom_controls_enabled]
120+
121+
- (void)setCustomSwipeGesture {
122+
// [START set_custom_swipe_gesture]
123+
GADNativeAdCustomClickGestureOptions *swipeGestureOptions =
124+
[[GADNativeAdCustomClickGestureOptions alloc]
125+
initWithSwipeGestureDirection:UISwipeGestureRecognizerDirectionRight
126+
tapsAllowed:YES];
127+
128+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:nativeAdUnitID
129+
rootViewController:self
130+
adTypes:@[ GADAdLoaderAdTypeNative ]
131+
options:@[ swipeGestureOptions ]];
132+
// [END set_custom_swipe_gesture]
133+
}
134+
135+
#pragma mark - GADNativeAdDelegate
136+
137+
// [START custom_swipe_gesture_delegate]
138+
// Called when a swipe gesture click is recorded, as configured in
139+
// GADNativeAdCustomClickGestureOptions.
140+
- (void)nativeAdDidRecordSwipeGestureClick:(GADNativeAd *)nativeAd {
141+
NSLog(@"A swipe gesture click has occurred.");
142+
}
143+
144+
// Called when a swipe gesture click or a tap click is recorded.
145+
- (void)nativeAdDidRecordClick:(GADNativeAd *)nativeAd {
146+
NSLog(@"A swipe gesture click or tap click has occurred.");
147+
}
148+
// [END custom_swipe_gesture_delegate]
149+
150+
NS_ASSUME_NONNULL_END
151+
152+
@end

Objective-C/advanced/APIDemo/APIDemo/Snippets/ResponseInfoSnippets.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ @implementation ResponseInfoSnippets
2525

2626
// [START get_ad_source_name]
2727
- (NSString *)uniqueAdSourceNameForAdNetworkResponseInfo:
28-
(AdNetworkResponseInfo *)loadedAdNetworkResponseInfo {
28+
(GADAdNetworkResponseInfo *)loadedAdNetworkResponseInfo {
2929
NSString *adSourceName = loadedAdNetworkResponseInfo.adSourceName;
3030
if ([adSourceName isEqualToString:@"Custom Event"]) {
3131
if ([loadedAdNetworkResponseInfo.adNetworkClassName isEqualToString:@"SampleCustomEvent"]) {

Swift/advanced/APIDemo/APIDemo.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
507818F8219A418100E5A44A /* AdManagerCustomVideoControlsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507818F1219A417F00E5A44A /* AdManagerCustomVideoControlsController.swift */; };
2525
507818F9219A418100E5A44A /* AdManagerAppEventsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507818F2219A418000E5A44A /* AdManagerAppEventsViewController.swift */; };
2626
507818FA219A418100E5A44A /* AdManagerFluidAdSizeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507818F3219A418100E5A44A /* AdManagerFluidAdSizeViewController.swift */; };
27+
A8265F6D2E4F882600A9C150 /* BannerSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8265F6C2E4F882600A9C150 /* BannerSnippets.swift */; };
28+
A8265F6F2E4F883500A9C150 /* ResponseInfoSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8265F6E2E4F883500A9C150 /* ResponseInfoSnippets.swift */; };
29+
A8265F712E4F884500A9C150 /* NativeAdOptionsSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8265F702E4F884100A9C150 /* NativeAdOptionsSnippets.swift */; };
2730
A846F1C12E2583D200F96E49 /* RewardedAdSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A846F1C02E2583CF00F96E49 /* RewardedAdSnippets.swift */; };
2831
A86568AB2E254CD500D360C3 /* ATTSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86568AA2E254CD100D360C3 /* ATTSnippets.swift */; };
2932
A8B650362DD63E0300AE1D3F /* RequestConfigurationSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B650352DD63DFC00AE1D3F /* RequestConfigurationSnippets.swift */; };
@@ -56,6 +59,9 @@
5659
507818F1219A417F00E5A44A /* AdManagerCustomVideoControlsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdManagerCustomVideoControlsController.swift; sourceTree = "<group>"; };
5760
507818F2219A418000E5A44A /* AdManagerAppEventsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdManagerAppEventsViewController.swift; sourceTree = "<group>"; };
5861
507818F3219A418100E5A44A /* AdManagerFluidAdSizeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdManagerFluidAdSizeViewController.swift; sourceTree = "<group>"; };
62+
A8265F6C2E4F882600A9C150 /* BannerSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerSnippets.swift; sourceTree = "<group>"; };
63+
A8265F6E2E4F883500A9C150 /* ResponseInfoSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseInfoSnippets.swift; sourceTree = "<group>"; };
64+
A8265F702E4F884100A9C150 /* NativeAdOptionsSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAdOptionsSnippets.swift; sourceTree = "<group>"; };
5965
A846F1C02E2583CF00F96E49 /* RewardedAdSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RewardedAdSnippets.swift; sourceTree = "<group>"; };
6066
A86568AA2E254CD100D360C3 /* ATTSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTSnippets.swift; sourceTree = "<group>"; };
6167
A8B650352DD63DFC00AE1D3F /* RequestConfigurationSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestConfigurationSnippets.swift; sourceTree = "<group>"; };
@@ -135,7 +141,10 @@
135141
isa = PBXGroup;
136142
children = (
137143
A86568AA2E254CD100D360C3 /* ATTSnippets.swift */,
144+
A8265F6C2E4F882600A9C150 /* BannerSnippets.swift */,
145+
A8265F702E4F884100A9C150 /* NativeAdOptionsSnippets.swift */,
138146
A8B650352DD63DFC00AE1D3F /* RequestConfigurationSnippets.swift */,
147+
A8265F6E2E4F883500A9C150 /* ResponseInfoSnippets.swift */,
139148
A846F1C02E2583CF00F96E49 /* RewardedAdSnippets.swift */,
140149
);
141150
path = Snippets;
@@ -241,12 +250,15 @@
241250
507818F5219A418100E5A44A /* AdManagerCategoryExclusionsTableViewController.swift in Sources */,
242251
4AA7D6911C625A1200DFD2EB /* AppDelegate.swift in Sources */,
243252
4AA7D6AC1C626EE700DFD2EB /* AdMobAdDelegateViewController.swift in Sources */,
253+
A8265F712E4F884500A9C150 /* NativeAdOptionsSnippets.swift in Sources */,
244254
507818F7219A418100E5A44A /* AdManagerCustomTargetingViewController.swift in Sources */,
245255
AED111262032151200EA4BEE /* SimpleNativeAdView.swift in Sources */,
246256
507818F9219A418100E5A44A /* AdManagerAppEventsViewController.swift in Sources */,
247257
5038FC6F251144E300750F9C /* MainViewController.swift in Sources */,
258+
A8265F6F2E4F883500A9C150 /* ResponseInfoSnippets.swift in Sources */,
248259
507818F8219A418100E5A44A /* AdManagerCustomVideoControlsController.swift in Sources */,
249260
507818FA219A418100E5A44A /* AdManagerFluidAdSizeViewController.swift in Sources */,
261+
A8265F6D2E4F882600A9C150 /* BannerSnippets.swift in Sources */,
250262
A86568AB2E254CD500D360C3 /* ATTSnippets.swift in Sources */,
251263
4A7A6CD71C76237500FB1A32 /* Constants.swift in Sources */,
252264
507818F6219A418100E5A44A /* AdManagerPPIDViewController.swift in Sources */,

0 commit comments

Comments
 (0)