Skip to content

Commit b389ed7

Browse files
nventimiglicopybara-github
authored andcommitted
Added snippets for server to server requests.
PiperOrigin-RevId: 805096286
1 parent 66edbf8 commit b389ed7

File tree

6 files changed

+432
-4
lines changed

6 files changed

+432
-4
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1C1F6FCB2E70EA9300B6D6F5 /* AdManagerSCARSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C1F6FC92E70EA9300B6D6F5 /* AdManagerSCARSnippets.m */; };
11+
1C1F6FCC2E70EA9300B6D6F5 /* AdmobSCARSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C1F6FCA2E70EA9300B6D6F5 /* AdmobSCARSnippets.m */; };
1012
1CD352992C9CE6A600534FCC /* CustomControls.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1CD352982C9CE6A600534FCC /* CustomControls.xib */; };
1113
4A96E7211B856D5000031470 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A96E7201B856D5000031470 /* main.m */; };
1214
4A96E7241B856D5000031470 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A96E7231B856D5000031470 /* AppDelegate.m */; };
@@ -35,13 +37,14 @@
3537
AED1111020320CA900EA4BEE /* NativeAdView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AED1110F20320CA800EA4BEE /* NativeAdView.xib */; };
3638
AEE8DA9F201BD7A6008792E6 /* SimpleNativeAdView.m in Sources */ = {isa = PBXBuildFile; fileRef = AEE8DA9D201BD7A6008792E6 /* SimpleNativeAdView.m */; };
3739
AEE8DAA5201BDCA9008792E6 /* CustomControlsView.m in Sources */ = {isa = PBXBuildFile; fileRef = AEE8DAA4201BDCA9008792E6 /* CustomControlsView.m */; };
38-
EF25D0222E4B916800688F43 /* BannerSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = EF25D0212E4B916800688F43 /* BannerSnippets.m */; };
3940
EF25D0242E4B917500688F43 /* ResponseInfoSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = EF25D0232E4B917500688F43 /* ResponseInfoSnippets.m */; };
4041
EF25D0262E4B95F400688F43 /* RewardedInterstitialAdSnippets.m in Sources */ = {isa = PBXBuildFile; fileRef = EF25D0252E4B917E00688F43 /* RewardedInterstitialAdSnippets.m */; };
4142
EF98F6062BD948C900FDCA41 /* CollapsibleBannerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EF98F6052BD948C900FDCA41 /* CollapsibleBannerViewController.m */; };
4243
/* End PBXBuildFile section */
4344

4445
/* Begin PBXFileReference section */
46+
1C1F6FC92E70EA9300B6D6F5 /* AdManagerSCARSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AdManagerSCARSnippets.m; sourceTree = "<group>"; };
47+
1C1F6FCA2E70EA9300B6D6F5 /* AdmobSCARSnippets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AdmobSCARSnippets.m; sourceTree = "<group>"; };
4548
1CD352982C9CE6A600534FCC /* CustomControls.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CustomControls.xib; sourceTree = "<group>"; };
4649
4A96E71B1B856D5000031470 /* APIDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = APIDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
4750
4A96E71F1B856D5000031470 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -190,6 +193,8 @@
190193
A8B6503B2DD63FAB00AE1D3F /* Snippets */ = {
191194
isa = PBXGroup;
192195
children = (
196+
1C1F6FC92E70EA9300B6D6F5 /* AdManagerSCARSnippets.m */,
197+
1C1F6FCA2E70EA9300B6D6F5 /* AdmobSCARSnippets.m */,
193198
EF25D0252E4B917E00688F43 /* RewardedInterstitialAdSnippets.m */,
194199
EF25D0232E4B917500688F43 /* ResponseInfoSnippets.m */,
195200
EF25D0212E4B916800688F43 /* BannerSnippets.m */,
@@ -314,6 +319,8 @@
314319
A8265F742E4F8AE000A9C150 /* BannerSnippets.m in Sources */,
315320
A8265F752E4F8AE000A9C150 /* ResponseInfoSnippets.m in Sources */,
316321
50DC0CFA212F1C4000424CC7 /* GAMFluidAdSizeViewController.m in Sources */,
322+
1C1F6FCB2E70EA9300B6D6F5 /* AdManagerSCARSnippets.m in Sources */,
323+
1C1F6FCC2E70EA9300B6D6F5 /* AdmobSCARSnippets.m in Sources */,
317324
A8B6503A2DD63FA500AE1D3F /* RequestConfigurationSnippets.m in Sources */,
318325
AEE8DAA5201BDCA9008792E6 /* CustomControlsView.m in Sources */,
319326
AEE8DA9F201BD7A6008792E6 /* SimpleNativeAdView.m in Sources */,
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
@interface AdManagerSCARSnippets : NSObject
21+
- (void)loadNative:(NSString *)adUnitID;
22+
- (void)loadBanner:(NSString *)adUnitID;
23+
- (void)loadNativePlusBanner:(NSString *)adUnitID;
24+
@end
25+
26+
@implementation AdManagerSCARSnippets
27+
28+
- (void)loadNative:(NSString *)adUnitID {
29+
// [START signal_request_native]
30+
// Specify the "signal_type_ad_manager_s2s" to
31+
// denote that the usage of QueryInfo is for Ad Manager S2S.
32+
GADNativeSignalRequest *signalRequest =
33+
[[GADNativeSignalRequest alloc] initWithSignalType:@"signal_type_ad_manager_s2s"];
34+
signalRequest.requestAgent = @"request_agent";
35+
signalRequest.adUnitID = adUnitID;
36+
37+
[GADMobileAds generateSignal:signalRequest
38+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
39+
if (error != nil) {
40+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
41+
return;
42+
}
43+
if (signal == nil) {
44+
NSLog(@"Unexpected error - query info is nil.");
45+
return;
46+
}
47+
NSLog(@"Signal string: %@", signal.signalString);
48+
// TODO: Fetch the ad response using your generated signal.
49+
}];
50+
// [END signal_request_native]
51+
}
52+
53+
- (void)loadBanner:(NSString *)adUnitID {
54+
// [START signal_request_banner]
55+
// Specify the "signal_type_ad_manager_s2s" to
56+
// denote that the usage of QueryInfo is for Ad Manager S2S.
57+
GADBannerSignalRequest *signalRequest =
58+
[[GADBannerSignalRequest alloc] initWithSignalType:@"signal_type_ad_manager_s2s"];
59+
signalRequest.requestAgent = @"request_agent";
60+
signalRequest.adUnitID = adUnitID;
61+
signalRequest.adSize = GADPortraitInlineAdaptiveBannerAdSizeWithWidth(320);
62+
63+
[GADMobileAds generateSignal:signalRequest
64+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
65+
if (error != nil) {
66+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
67+
return;
68+
}
69+
if (signal == nil) {
70+
NSLog(@"Unexpected error - query info is nil.");
71+
return;
72+
}
73+
NSLog(@"Signal string: %@", signal.signalString);
74+
// TODO: Fetch the ad response using your generated signal.
75+
}];
76+
// [END signal_request_banner]
77+
}
78+
79+
- (void)loadNativePlusBanner:(NSString *)adUnitID {
80+
// [START signal_request_native_plus_banner]
81+
// Specify the "signal_type_ad_manager_s2s" to
82+
// denote that the usage of QueryInfo is for Ad Manager S2S.
83+
GADNativeSignalRequest *signalRequest =
84+
[[GADNativeSignalRequest alloc] initWithSignalType:@"signal_type_ad_manager_s2s"];
85+
signalRequest.requestAgent = @"request_agent";
86+
signalRequest.adUnitID = adUnitID;
87+
signalRequest.adLoaderAdTypes =
88+
[NSSet setWithArray:@[ GADAdLoaderAdTypeNative, GADAdLoaderAdTypeGAMBanner ]];
89+
signalRequest.adSizes = @[ @(GADPortraitInlineAdaptiveBannerAdSizeWithWidth(320)) ];
90+
91+
[GADMobileAds generateSignal:signalRequest
92+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
93+
if (error != nil) {
94+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
95+
return;
96+
}
97+
if (signal == nil) {
98+
NSLog(@"Unexpected error - query info is nil.");
99+
return;
100+
}
101+
NSLog(@"Signal string: %@", signal.signalString);
102+
// TODO: Fetch the ad response using your generated signal.
103+
}];
104+
// [END signal_request_native_plus_banner]
105+
}
106+
107+
@end
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
@interface AdmobSCARSnippets : NSObject
21+
- (void)loadNative:(NSString *)adUnitID;
22+
- (void)loadBanner:(NSString *)adUnitID;
23+
- (void)loadNativePlusBanner:(NSString *)adUnitID;
24+
@end
25+
26+
@implementation AdmobSCARSnippets
27+
28+
- (void)loadNative:(NSString *)adUnitID {
29+
// [START signal_request_native]
30+
// Replace REQUEST_TYPE with your request type.
31+
GADNativeSignalRequest *signalRequest =
32+
[[GADNativeSignalRequest alloc] initWithSignalType:@"REQUEST_TYPE"];
33+
signalRequest.requestAgent = @"request_agent";
34+
signalRequest.adUnitID = adUnitID;
35+
36+
[GADMobileAds generateSignal:signalRequest
37+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
38+
if (error != nil) {
39+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
40+
return;
41+
}
42+
if (signal == nil) {
43+
NSLog(@"Unexpected error - query info is nil.");
44+
return;
45+
}
46+
NSLog(@"Signal string: %@", signal.signalString);
47+
// TODO: Fetch the ad response using your generated signal.
48+
}];
49+
// [END signal_request_native]
50+
}
51+
52+
- (void)loadBanner:(NSString *)adUnitID {
53+
// [START signal_request_banner]
54+
// Replace REQUEST_TYPE with your request type.
55+
GADBannerSignalRequest *signalRequest =
56+
[[GADBannerSignalRequest alloc] initWithSignalType:@"REQUEST_TYPE"];
57+
signalRequest.requestAgent = @"request_agent";
58+
signalRequest.adUnitID = adUnitID;
59+
signalRequest.adSize = GADPortraitInlineAdaptiveBannerAdSizeWithWidth(320);
60+
61+
[GADMobileAds generateSignal:signalRequest
62+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
63+
if (error != nil) {
64+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
65+
return;
66+
}
67+
if (signal == nil) {
68+
NSLog(@"Unexpected error - query info is nil.");
69+
return;
70+
}
71+
NSLog(@"Signal string: %@", signal.signalString);
72+
// TODO: Fetch the ad response using your generated signal.
73+
}];
74+
// [END signal_request_banner]
75+
}
76+
77+
- (void)loadNativePlusBanner:(NSString *)adUnitID {
78+
// [START signal_request_native_plus_banner]
79+
// Replace REQUEST_TYPE with your request type.
80+
GADNativeSignalRequest *signalRequest =
81+
[[GADNativeSignalRequest alloc] initWithSignalType:@"REQUEST_TYPE"];
82+
signalRequest.requestAgent = @"request_agent";
83+
signalRequest.adUnitID = adUnitID;
84+
signalRequest.adLoaderAdTypes =
85+
[NSSet setWithArray:@[ GADAdLoaderAdTypeNative, GADAdLoaderAdTypeGAMBanner ]];
86+
signalRequest.adSizes = @[ @(GADPortraitInlineAdaptiveBannerAdSizeWithWidth(320)) ];
87+
88+
[GADMobileAds generateSignal:signalRequest
89+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
90+
if (error != nil) {
91+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
92+
return;
93+
}
94+
if (signal == nil) {
95+
NSLog(@"Unexpected error - query info is nil.");
96+
return;
97+
}
98+
NSLog(@"Signal string: %@", signal.signalString);
99+
// TODO: Fetch the ad response using your generated signal.
100+
}];
101+
// [END signal_request_native_plus_banner]
102+
}
103+
104+
@end

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1C1F6FC72E70E87700B6D6F5 /* AdManagerSCARSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1F6FC52E70E87700B6D6F5 /* AdManagerSCARSnippets.swift */; };
11+
1C1F6FC82E70E87700B6D6F5 /* AdmobSCARSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1F6FC62E70E87700B6D6F5 /* AdmobSCARSnippets.swift */; };
1012
1CD352682C9CC97200534FCC /* CustomControls.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1CD352672C9CC97200534FCC /* CustomControls.xib */; };
1113
4A7A6CD71C76237500FB1A32 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A7A6CD61C76237500FB1A32 /* Constants.swift */; };
1214
4AA7D6911C625A1200DFD2EB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA7D6901C625A1200DFD2EB /* AppDelegate.swift */; };
@@ -24,7 +26,6 @@
2426
507818F8219A418100E5A44A /* AdManagerCustomVideoControlsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507818F1219A417F00E5A44A /* AdManagerCustomVideoControlsController.swift */; };
2527
507818F9219A418100E5A44A /* AdManagerAppEventsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507818F2219A418000E5A44A /* AdManagerAppEventsViewController.swift */; };
2628
507818FA219A418100E5A44A /* AdManagerFluidAdSizeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507818F3219A418100E5A44A /* AdManagerFluidAdSizeViewController.swift */; };
27-
A8265F6D2E4F882600A9C150 /* BannerSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8265F6C2E4F882600A9C150 /* BannerSnippets.swift */; };
2829
A8265F6F2E4F883500A9C150 /* ResponseInfoSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8265F6E2E4F883500A9C150 /* ResponseInfoSnippets.swift */; };
2930
A8265F712E4F884500A9C150 /* NativeAdOptionsSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8265F702E4F884100A9C150 /* NativeAdOptionsSnippets.swift */; };
3031
A846F1C12E2583D200F96E49 /* RewardedAdSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A846F1C02E2583CF00F96E49 /* RewardedAdSnippets.swift */; };
@@ -35,14 +36,14 @@
3536
AED11120203213FC00EA4BEE /* UnifiedNativeAdView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AED11118203213F500EA4BEE /* UnifiedNativeAdView.xib */; };
3637
AED111262032151200EA4BEE /* SimpleNativeAdView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED111252032151200EA4BEE /* SimpleNativeAdView.swift */; };
3738
AED111282032174100EA4BEE /* CustomControlsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED111272032174100EA4BEE /* CustomControlsView.swift */; };
38-
EF25D0282E4B97F000688F43 /* BannerSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF25D0272E4B97F000688F43 /* BannerSnippets.swift */; };
39-
EF25D02A2E4B97FA00688F43 /* ResponseInfoSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF25D0292E4B97FA00688F43 /* ResponseInfoSnippets.swift */; };
4039
EF25D02C2E4B980C00688F43 /* RewardedInterstitialAdSnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF25D02B2E4B980100688F43 /* RewardedInterstitialAdSnippets.swift */; };
4140
EFC712462AD853D80014A2BF /* CollapsibleBannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFC712452AD853D80014A2BF /* CollapsibleBannerViewController.swift */; };
4241
/* End PBXBuildFile section */
4342

4443
/* Begin PBXFileReference section */
4544
15CB61211C7D0256000212DE /* APIDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "APIDemo-Bridging-Header.h"; sourceTree = "<group>"; };
45+
1C1F6FC52E70E87700B6D6F5 /* AdManagerSCARSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdManagerSCARSnippets.swift; sourceTree = "<group>"; };
46+
1C1F6FC62E70E87700B6D6F5 /* AdmobSCARSnippets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdmobSCARSnippets.swift; sourceTree = "<group>"; };
4647
1CD352672C9CC97200534FCC /* CustomControls.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CustomControls.xib; sourceTree = "<group>"; };
4748
4A7A6CD61C76237500FB1A32 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
4849
4AA7D68D1C625A1200DFD2EB /* APIDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = APIDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -146,6 +147,8 @@
146147
A8B650372DD63E0F00AE1D3F /* Snippets */ = {
147148
isa = PBXGroup;
148149
children = (
150+
1C1F6FC52E70E87700B6D6F5 /* AdManagerSCARSnippets.swift */,
151+
1C1F6FC62E70E87700B6D6F5 /* AdmobSCARSnippets.swift */,
149152
EF25D02B2E4B980100688F43 /* RewardedInterstitialAdSnippets.swift */,
150153
EF25D0292E4B97FA00688F43 /* ResponseInfoSnippets.swift */,
151154
EF25D0272E4B97F000688F43 /* BannerSnippets.swift */,
@@ -256,6 +259,8 @@
256259
buildActionMask = 2147483647;
257260
files = (
258261
4AA7D6AA1C626E7000DFD2EB /* AdMobAdTargetingTableViewController.swift in Sources */,
262+
1C1F6FC72E70E87700B6D6F5 /* AdManagerSCARSnippets.swift in Sources */,
263+
1C1F6FC82E70E87700B6D6F5 /* AdmobSCARSnippets.swift in Sources */,
259264
507818F5219A418100E5A44A /* AdManagerCategoryExclusionsTableViewController.swift in Sources */,
260265
4AA7D6911C625A1200DFD2EB /* AppDelegate.swift in Sources */,
261266
4AA7D6AC1C626EE700DFD2EB /* AdMobAdDelegateViewController.swift in Sources */,

0 commit comments

Comments
 (0)