Skip to content

Commit 075528b

Browse files
nventimiglicopybara-github
authored andcommitted
Added snippets for server to server requests.
PiperOrigin-RevId: 805509264
1 parent d719655 commit 075528b

File tree

3 files changed

+198
-1
lines changed

3 files changed

+198
-1
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: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
// Create a signal request for an ad.
31+
// Specify the "signal_type_ad_manager_s2s" to
32+
// denote that the usage of QueryInfo is for Ad Manager S2S.
33+
GADNativeSignalRequest *signalRequest =
34+
[[GADNativeSignalRequest alloc] initWithSignalType:@"signal_type_ad_manager_s2s"];
35+
signalRequest.requestAgent = @"REQUEST_AGENT";
36+
signalRequest.adUnitID = adUnitID;
37+
38+
[GADMobileAds generateSignal:signalRequest
39+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
40+
if (error != nil) {
41+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
42+
return;
43+
}
44+
if (signal == nil) {
45+
NSLog(@"Unexpected error - query info is nil.");
46+
return;
47+
}
48+
NSLog(@"Signal string: %@", signal.signalString);
49+
// TODO: Fetch the ad response using your generated signal.
50+
}];
51+
// [END signal_request_native]
52+
}
53+
54+
- (void)loadBanner:(NSString *)adUnitID {
55+
// [START signal_request_banner]
56+
// Create a signal request for an ad.
57+
// Specify the "signal_type_ad_manager_s2s" to
58+
// denote that the usage of QueryInfo is for Ad Manager S2S.
59+
GADBannerSignalRequest *signalRequest =
60+
[[GADBannerSignalRequest alloc] initWithSignalType:@"signal_type_ad_manager_s2s"];
61+
signalRequest.requestAgent = @"REQUEST_AGENT";
62+
signalRequest.adUnitID = adUnitID;
63+
// Refer to the AdSize class for available ad sizes.
64+
signalRequest.adSize = GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(320);
65+
66+
[GADMobileAds generateSignal:signalRequest
67+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
68+
if (error != nil) {
69+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
70+
return;
71+
}
72+
if (signal == nil) {
73+
NSLog(@"Unexpected error - query info is nil.");
74+
return;
75+
}
76+
NSLog(@"Signal string: %@", signal.signalString);
77+
// TODO: Fetch the ad response using your generated signal.
78+
}];
79+
// [END signal_request_banner]
80+
}
81+
82+
- (void)loadNativePlusBanner:(NSString *)adUnitID {
83+
// [START signal_request_native_plus_banner]
84+
// Create a signal request for an ad.
85+
// Specify the "signal_type_ad_manager_s2s" to
86+
// denote that the usage of QueryInfo is for Ad Manager S2S.
87+
GADNativeSignalRequest *signalRequest =
88+
[[GADNativeSignalRequest alloc] initWithSignalType:@"signal_type_ad_manager_s2s"];
89+
signalRequest.requestAgent = @"request_agent";
90+
signalRequest.adUnitID = adUnitID;
91+
signalRequest.adLoaderAdTypes =
92+
[NSSet setWithArray:@[ GADAdLoaderAdTypeNative, GADAdLoaderAdTypeGAMBanner ]];
93+
// Refer to the AdSize class for available ad sizes.
94+
signalRequest.adSizes = @[ @(GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(320)) ];
95+
96+
[GADMobileAds generateSignal:signalRequest
97+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
98+
if (error != nil) {
99+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
100+
return;
101+
}
102+
if (signal == nil) {
103+
NSLog(@"Unexpected error - query info is nil.");
104+
return;
105+
}
106+
NSLog(@"Signal string: %@", signal.signalString);
107+
// TODO: Fetch the ad response using your generated signal.
108+
}];
109+
// [END signal_request_native_plus_banner]
110+
}
111+
112+
@end
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
@end
24+
25+
@implementation AdmobSCARSnippets
26+
27+
- (void)loadNative:(NSString *)adUnitID {
28+
// [START signal_request_native]
29+
// Create a signal request for an ad.
30+
GADNativeSignalRequest *signalRequest =
31+
[[GADNativeSignalRequest alloc] initWithSignalType:@"SIGNAL_TYPE"];
32+
signalRequest.requestAgent = @"REQUEST_AGENT";
33+
signalRequest.adUnitID = adUnitID;
34+
35+
[GADMobileAds generateSignal:signalRequest
36+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
37+
if (error != nil) {
38+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
39+
return;
40+
}
41+
if (signal == nil) {
42+
NSLog(@"Unexpected error - signal is nil.");
43+
return;
44+
}
45+
NSLog(@"Signal string: %@", signal.signalString);
46+
// TODO: Fetch the ad response using your generated signal.
47+
}];
48+
// [END signal_request_native]
49+
}
50+
51+
- (void)loadBanner:(NSString *)adUnitID {
52+
// [START signal_request_banner]
53+
// Create a signal request for an ad.
54+
// Contact your account manager for your assigned signal type.
55+
GADBannerSignalRequest *signalRequest =
56+
[[GADBannerSignalRequest alloc] initWithSignalType:@"SIGNAL_TYPE"];
57+
signalRequest.requestAgent = @"REQUEST_AGENT";
58+
signalRequest.adUnitID = adUnitID;
59+
// Refer to the AdSize class for available ad sizes.
60+
signalRequest.adSize = GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(320);
61+
62+
[GADMobileAds generateSignal:signalRequest
63+
completionHandler:^(GADSignal *_Nullable signal, NSError *_Nullable error) {
64+
if (error != nil) {
65+
NSLog(@"Error getting ad info: %@", error.localizedDescription);
66+
return;
67+
}
68+
if (signal == nil) {
69+
NSLog(@"Unexpected error - Signal is nil.");
70+
return;
71+
}
72+
NSLog(@"Signal string: %@", signal.signalString);
73+
// TODO: Fetch the ad response using your generated signal.
74+
}];
75+
// [END signal_request_banner]
76+
}
77+
78+
@end

0 commit comments

Comments
 (0)