Skip to content

Commit a82ae4f

Browse files
Nicholas Ventimigliacopybara-github
authored andcommitted
Updated native ad option snippets.
PiperOrigin-RevId: 925465584
1 parent ae58229 commit a82ae4f

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// Copyright (C) 2026 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 <UIKit/UIKit.h>
18+
#import <GoogleMobileAds/GoogleMobileAds.h>
19+
20+
NS_ASSUME_NONNULL_BEGIN
21+
22+
// Replace this ad unit ID with your own ad unit ID.
23+
static NSString *const kNativeAdUnitID = @"/21775744923/example/native";
24+
25+
// Demonstrates how to use custom click gesture options for native ads in Google Ad Manager.
26+
@interface AdManagerNativeAdOptionsSnippets : UIViewController <GADNativeAdDelegate>
27+
// The ad loader.
28+
@property(nonatomic, strong) GADAdLoader *adLoader;
29+
@end
30+
31+
@implementation AdManagerNativeAdOptionsSnippets
32+
33+
// Sets up a GADAdLoader with custom swipe gesture options.
34+
- (void)setCustomSwipeGesture {
35+
// [START set_custom_swipe_gesture]
36+
GADNativeAdCustomClickGestureOptions *swipeGestureOptions =
37+
[[GADNativeAdCustomClickGestureOptions alloc]
38+
initWithSwipeGestureDirection:UISwipeGestureRecognizerDirectionRight
39+
tapsAllowed:YES];
40+
41+
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:kNativeAdUnitID
42+
rootViewController:self
43+
adTypes:@[ GADAdLoaderAdTypeNative ]
44+
options:@[ swipeGestureOptions ]];
45+
// [END set_custom_swipe_gesture]
46+
}
47+
48+
#pragma mark - GADNativeAdDelegate
49+
50+
// Called when a swipe gesture click is recorded, as configured in
51+
// GADNativeAdCustomClickGestureOptions.
52+
// [START custom_swipe_gesture_delegate]
53+
- (void)nativeAdDidRecordSwipeGestureClick:(GADNativeAd *)nativeAd {
54+
NSLog(@"A swipe gesture click has occurred.");
55+
}
56+
57+
// Called when a swipe gesture click or a tap click is recorded.
58+
- (void)nativeAdDidRecordClick:(GADNativeAd *)nativeAd {
59+
NSLog(@"A swipe gesture click or tap click has occurred.");
60+
}
61+
// [END custom_swipe_gesture_delegate]
62+
63+
@end
64+
65+
NS_ASSUME_NONNULL_END
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// Copyright (C) 2026 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
18+
19+
private class AdManagerNativeAdOptionsSnippets: UIViewController, NativeAdDelegate {
20+
21+
// Replace this ad unit ID with your own ad unit ID.
22+
private let nativeAdUnitID = "/21775744923/example/native"
23+
private var adLoader: AdLoader?
24+
25+
private func setCustomSwipeGesture() {
26+
// [START set_custom_swipe_gesture]
27+
var options: [GADAdLoaderOptions]? = nil
28+
adLoader = AdLoader(
29+
adUnitID: nativeAdUnitID,
30+
rootViewController: self,
31+
adTypes: [.native],
32+
options: options)
33+
// [END set_custom_swipe_gesture]
34+
}
35+
36+
// [START custom_swipe_gesture_delegate]
37+
/// Notifies the delegate that a swipe gesture click was recorded, as configured in
38+
/// NativeAdCustomClickGestureOptions.
39+
func nativeAdDidRecordSwipeGestureClick(_ nativeAd: NativeAd) {
40+
print("A swipe gesture click has occurred.")
41+
}
42+
43+
/// Notifies the delegate that a swipe gesture click or a tap click was recorded.
44+
func nativeAdDidRecordClick(_ nativeAd: NativeAd) {
45+
print("A swipe gesture click or tap click has occurred.")
46+
}
47+
// [END custom_swipe_gesture_delegate]
48+
}

0 commit comments

Comments
 (0)