Skip to content

Commit a84c299

Browse files
nventimiglicopybara-github
authored andcommitted
Added snippets for server to server requests.
PiperOrigin-RevId: 805508507
1 parent 7680a46 commit a84c299

File tree

3 files changed

+147
-3
lines changed

3 files changed

+147
-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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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) async {
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+
do {
31+
let signal = try await MobileAds.generateSignal(signalRequest)
32+
print("Signal string: \(signal.signal)")
33+
// TODO: Fetch the ad response using your generated signal.
34+
} catch {
35+
print("Error getting ad info: \(error.localizedDescription)")
36+
}
37+
// [END signal_request_native]
38+
}
39+
40+
func loadBanner(adUnitID: String) async {
41+
// [START signal_request_banner]
42+
// Create a signal request for an ad.
43+
// Specify the "signal_type_ad_manager_s2s" to
44+
// denote that the usage of QueryInfo is for Ad Manager S2S.
45+
let signalRequest = BannerSignalRequest(signalType: "signal_type_ad_manager_s2s")
46+
signalRequest.requestAgent = "REQUEST_AGENT"
47+
signalRequest.adUnitID = adUnitID
48+
// Refer to the AdSize class for available ad sizes.
49+
signalRequest.adSize = currentOrientationInlineAdaptiveBanner(width: 320)
50+
51+
do {
52+
let signal = try await MobileAds.generateSignal(signalRequest)
53+
print("Signal string: \(signal.signal)")
54+
// TODO: Fetch the ad response using your generated signal.
55+
} catch {
56+
print("Error getting ad info: \(error.localizedDescription)")
57+
}
58+
// [END signal_request_banner]
59+
}
60+
61+
func loadNativePlusBanner(adUnitID: String) async {
62+
// [START signal_request_native_plus_banner]
63+
// Create a signal request for an ad.
64+
// Specify the "signal_type_ad_manager_s2s" to
65+
// denote that the usage of QueryInfo is for Ad Manager S2S.
66+
let signalRequest = NativeSignalRequest(signalType: "signal_type_ad_manager_s2s")
67+
signalRequest.requestAgent = "REQUEST_AGENT"
68+
signalRequest.adUnitID = adUnitID
69+
signalRequest.adLoaderAdTypes = [AdLoaderAdType.native, AdLoaderAdType.adManagerBanner]
70+
// Refer to the AdSize class for available ad sizes.
71+
signalRequest.adSizes = [nsValue(for: currentOrientationInlineAdaptiveBanner(width: 320))]
72+
73+
do {
74+
let signal = try await MobileAds.generateSignal(signalRequest)
75+
print("Signal string: \(signal.signal)")
76+
// TODO: Fetch the ad response using your generated signal.
77+
} catch {
78+
print("Error getting ad info: \(error.localizedDescription)")
79+
}
80+
// [END signal_request_native_plus_banner]
81+
}
82+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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) async {
22+
// [START signal_request_native]
23+
// Create a signal request for an ad.
24+
let signalRequest = NativeSignalRequest(signalType: "SIGNAL_TYPE")
25+
signalRequest.requestAgent = "REQUEST_AGENT"
26+
signalRequest.adUnitID = adUnitID
27+
28+
do {
29+
let signal = try await MobileAds.generateSignal(signalRequest)
30+
print("Signal string: \(signal.signal)")
31+
// TODO: Fetch the ad response using your generated signal.
32+
} catch {
33+
print("Error getting ad info: \(error.localizedDescription)")
34+
}
35+
// [END signal_request_native]
36+
}
37+
38+
func loadBanner(adUnitID: String) async {
39+
// [START signal_request_banner]
40+
// Create a signal request for an ad.
41+
let signalRequest = BannerSignalRequest(signalType: "SIGNAL_TYPE")
42+
signalRequest.requestAgent = "REQUEST_AGENT"
43+
signalRequest.adUnitID = adUnitID
44+
// Refer to the AdSize class for available ad sizes.
45+
signalRequest.adSize = GADAdSize.portraitInlineAdaptiveBanner(width: 320)
46+
47+
do {
48+
let signal = try await MobileAds.generateSignal(signalRequest)
49+
print("Signal string: \(signal.signal)")
50+
// TODO: Fetch the ad response using your generated signal.
51+
} catch {
52+
print("Error getting ad info: \(error.localizedDescription)")
53+
}
54+
// [END signal_request_banner]
55+
}
56+
57+
}

0 commit comments

Comments
 (0)