Skip to content

Commit 0acc6cd

Browse files
nventimiglicopybara-github
authored andcommitted
Added snippets for server to server requests.
PiperOrigin-RevId: 805508507
1 parent d719655 commit 0acc6cd

File tree

3 files changed

+194
-3
lines changed

3 files changed

+194
-3
lines changed

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 */,
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (C) 2025 Google, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
import GoogleMobileAds
17+
import UIKit
18+
19+
class AdManagerSCARSnippets: NSObject {
20+
21+
func loadNative(adUnitID: String) {
22+
// [START signal_request_native]
23+
// Create a signal request for an ad.
24+
// Specify the "signal_type_ad_manager_s2s" to
25+
// denote that the usage of QueryInfo is for Ad Manager S2S.
26+
let signalRequest = NativeSignalRequest(signalType: "signal_type_ad_manager_s2s")
27+
signalRequest.requestAgent = "REQUEST_AGENT"
28+
signalRequest.adUnitID = adUnitID
29+
30+
MobileAds.generateSignal(signalRequest) { [weak self] signal, error in
31+
guard self != nil else { return }
32+
33+
if let error = error {
34+
print("Error getting ad info: \(error.localizedDescription)")
35+
return
36+
}
37+
38+
guard let signal = signal else {
39+
print("Unexpected error - signal info is nil.")
40+
return
41+
}
42+
43+
print("Signal string: \(signal.signal)")
44+
// TODO: Fetch the ad response using your generated signal.
45+
}
46+
// [END signal_request_native]
47+
}
48+
49+
func loadBanner(adUnitID: String) {
50+
// [START signal_request_banner]
51+
// Create a signal request for an ad.
52+
// Specify the "signal_type_ad_manager_s2s" to
53+
// denote that the usage of QueryInfo is for Ad Manager S2S.
54+
let signalRequest = BannerSignalRequest(signalType: "signal_type_ad_manager_s2s")
55+
signalRequest.requestAgent = "REQUEST_AGENT"
56+
signalRequest.adUnitID = adUnitID
57+
// Refer to the AdSize class for available ad sizes.
58+
signalRequest.adSize = portraitInlineAdaptiveBanner(width: 320)
59+
60+
MobileAds.generateSignal(signalRequest) { [weak self] signal, error in
61+
guard self != nil else { return }
62+
63+
if let error = error {
64+
print("Error getting ad info: \(error.localizedDescription)")
65+
return
66+
}
67+
68+
guard let signal = signal else {
69+
print("Unexpected error - signal info is nil.")
70+
return
71+
}
72+
73+
print("Signal string: \(signal.signal)")
74+
// TODO: Fetch the ad response using your generated signal.
75+
}
76+
// [END signal_request_banner]
77+
}
78+
79+
func loadNativePlusBanner(adUnitID: String) {
80+
// [START signal_request_native_plus_banner]
81+
// Create a signal request for an ad.
82+
// Specify the "signal_type_ad_manager_s2s" to
83+
// denote that the usage of QueryInfo is for Ad Manager S2S.
84+
let signalRequest = NativeSignalRequest(signalType: "signal_type_ad_manager_s2s")
85+
signalRequest.requestAgent = "REQUEST_AGENT"
86+
signalRequest.adUnitID = adUnitID
87+
signalRequest.adLoaderAdTypes = [AdLoaderAdType.native, AdLoaderAdType.adManagerBanner]
88+
// Refer to the AdSize class for available ad sizes.
89+
signalRequest.adSizes = [nsValue(for: portraitInlineAdaptiveBanner(width: 320))]
90+
91+
MobileAds.generateSignal(signalRequest) { [weak self] signal, error in
92+
guard self != nil else { return }
93+
94+
if let error = error {
95+
print("Error getting ad info: \(error.localizedDescription)")
96+
return
97+
}
98+
99+
guard let signal = signal else {
100+
print("Unexpected error - signal info is nil.")
101+
return
102+
}
103+
104+
print("Signal string: \(signal.signal)")
105+
// TODO: Fetch the ad response using your generated signal.
106+
}
107+
// [END signal_request_native_plus_banner]
108+
}
109+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (C) 2025 Google, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
import GoogleMobileAds
17+
import UIKit
18+
19+
class AdmobSCARSnippets: NSObject {
20+
21+
func loadNative(adUnitID: String) {
22+
// [START signal_request_native]
23+
// Create a signal request for an ad.
24+
// Contact your account manager for your assigned signal type.
25+
let signalRequest = NativeSignalRequest(signalType: "REQUEST_TYPE")
26+
signalRequest.requestAgent = "REQUEST_AGENT"
27+
signalRequest.adUnitID = adUnitID
28+
29+
MobileAds.generateSignal(signalRequest) { [weak self] signal, error in
30+
guard self != nil else { return }
31+
32+
if let error = error {
33+
print("Error getting ad info: \(error.localizedDescription)")
34+
return
35+
}
36+
37+
guard let signal = signal else {
38+
print("Unexpected error - signal info is nil.")
39+
return
40+
}
41+
42+
print("Signal string: \(signal.signal)")
43+
// TODO: Fetch the ad response using your generated signal.
44+
}
45+
// [END signal_request_native]
46+
}
47+
48+
func loadBanner(adUnitID: String) {
49+
// [START signal_request_banner]
50+
// Create a signal request for an ad.
51+
// Contact your account manager for your assigned signal type.
52+
let signalRequest = BannerSignalRequest(signalType: "REQUEST_TYPE")
53+
signalRequest.requestAgent = "REQUEST_AGENT"
54+
signalRequest.adUnitID = adUnitID
55+
// Refer to the AdSize class for available ad sizes.
56+
signalRequest.adSize = portraitInlineAdaptiveBanner(width: 320)
57+
58+
MobileAds.generateSignal(signalRequest) { [weak self] signal, error in
59+
guard self != nil else { return }
60+
61+
if let error = error {
62+
print("Error getting ad info: \(error.localizedDescription)")
63+
return
64+
}
65+
66+
guard let signal = signal else {
67+
print("Unexpected error - signal info is nil.")
68+
return
69+
}
70+
71+
print("Signal string: \(signal.signal)")
72+
// TODO: Fetch the ad response using your generated signal.
73+
}
74+
// [END signal_request_banner]
75+
}
76+
77+
}

0 commit comments

Comments
 (0)