<br />

Native ads have many advanced features that allow you to make additional
customizations and make the best possible ad experience. This guide shows you
how to use the advanced features of native ads.

## Prerequisites

- Integrate the [Native ad format](https://developers.google.com/admob/ios/native.md.txt).

## Asset controls

This section details how to customize the creative assets in your native ads.
You have the option to specify a preferred aspect ratio for media assets and
how the image assets are downloaded and displayed.

### Preferred media aspect ratio controls

Media Aspect Ratio Controls let you specify a preference for the aspect ratio of
ad creatives.

> [!IMPORTANT]
> **Important:** Use of this API does not guarantee that all ad creatives will meet the preference specified.

Set [`GADNativeAdMediaAdLoaderOptions mediaAspectRatio`](https://developers.google.com/admob/ios/api/reference/Classes/GADNativeAdMediaAdLoaderOptions.md.txt)
with a [`GADMediaAspectRatio`](https://developers.google.com/admob/ios/api/reference/Enums/GADMediaAspectRatio.md.txt).

- When unset, the returned ad can have any media aspect ratio.

- When set, you will be able to improve the user experience by specifying the
  preferred type of aspect ratio.

The following example instructs the SDK to prefer a return image or video with a
specific aspect ratio.

### Swift

```swift
let nativeOptions = NativeAdMediaAdLoaderOptions()
nativeOptions.mediaAspectRatio = .any

adLoader = AdLoader(
  adUnitID: "nativeAdUnitID",
  rootViewController: self,
  adTypes: [.native],
  options: [nativeOptions])
```

### Objective-C

```objective-c
GADNativeAdMediaAdLoaderOptions *nativeOptions = [[GADNativeAdMediaAdLoaderOptions alloc] init];
nativeOptions.mediaAspectRatio = GADMediaAspectRatioAny;

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"nativeAdUnitID"
                                   rootViewController:self
                                              adTypes:@[ GADAdLoaderAdTypeNative ]
                                              options:@[ nativeOptions ]];
```

Replace <var translate="no">nativeAdUnitID</var> with your ad unit ID.

### Image download control

Image download control lets you decide if image assets or only URIs are
returned by the SDK.

Set [`GADNativeAdImageAdLoaderOptions disableImageLoading`](https://developers.google.com/admob/ios/api/reference/Classes/GADNativeAdImageAdLoaderOptions.md.txt#disableimageloading)
with a `BOOL` value.

- Image download control are disabled by default.

- When disabled, Google Mobile Ads SDK populates both the image and the URI for you.

- When enabled, the SDK instead populates just the URI, allowing you to download
  the actual images at your discretion.

The following example instructs the SDK to return just the URI.

<br />

### Swift

```swift
let nativeOptions = NativeAdImageAdLoaderOptions()
nativeOptions.isImageLoadingDisabled = true

adLoader = AdLoader(
  adUnitID: "nativeAdUnitID",
  rootViewController: self,
  adTypes: [.native],
  options: [nativeOptions])
```

### Objective-C

```objective-c
GADNativeAdImageAdLoaderOptions *nativeOptions = [[GADNativeAdImageAdLoaderOptions alloc] init];
nativeOptions.disableImageLoading = YES;

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"nativeAdUnitID"
                                   rootViewController:self
                                              adTypes:@[ GADAdLoaderAdTypeNative ]
                                              options:@[ nativeOptions ]];
```

### Image payload controls

Some ads have a series of images rather than just one. Use this feature to
indicate whether your app is prepared to display all the images or just one.

<br />

- Image payload controls are disabled by default.

- When disabled, your app instructs the SDK to provide just the
  first image for any assets that contain a series.

- When enabled, your app indicates that it is prepared to display all the images
  for any assets that have more than one.

The following example instructs the SDK to return multiple image assets.

### Swift

```swift
let nativeOptions = NativeAdImageAdLoaderOptions()
nativeOptions.shouldRequestMultipleImages = true

adLoader = AdLoader(
  adUnitID: "nativeAdUnitID",
  rootViewController: self,
  adTypes: [.native],
  options: [nativeOptions])
```

### Objective-C

```objective-c
GADNativeAdImageAdLoaderOptions *nativeOptions = [[GADNativeAdImageAdLoaderOptions alloc] init];
nativeOptions.shouldRequestMultipleImages = YES;

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"nativeAdUnitID"
                                   rootViewController:self
                                              adTypes:@[ GADAdLoaderAdTypeNative ]
                                              options:@[ nativeOptions ]];
```

## AdChoices placements

This section details how to position the AdChoices overlay. You have the option
to set its placement to one of the four corners or render it within a custom
view.

### AdChoices position controls

The AdChoices position controls lets you choose which corner to render the
AdChoices icon.

Set [`GADNativeAdViewAdOptions preferredAdChoicesPosition`](https://developers.google.com/admob/ios/api/reference/Classes/GADNativeAdViewAdOptions.md.txt#preferredAdChoicesPosition)
with a [`GADAdChoicesPosition`](https://developers.google.com/admob/ios/api/reference/Enums/GADAdChoicesPosition.md.txt)
value.

- If unset, the AdChoices icon position is set to the top right.

- If set, AdChoices is placed at the custom position as requested.

The following example demonstrates how to set a custom AdChoices image position.

### Swift

```swift
let nativeOptions = NativeAdViewAdOptions()
nativeOptions.preferredAdChoicesPosition = .topRightCorner

adLoader = AdLoader(
  adUnitID: "nativeAdUnitID",
  rootViewController: self,
  adTypes: [.native],
  options: [nativeOptions])
```

### Objective-C

```objective-c
GADNativeAdViewAdOptions *nativeOptions = [[GADNativeAdViewAdOptions alloc] init];
nativeOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner;

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"nativeAdUnitID"
                                   rootViewController:self
                                              adTypes:@[ GADAdLoaderAdTypeNative ]
                                              options:@[ nativeOptions ]];
```

### AdChoices custom view


> [!WARNING]
> Warning: Access to this feature is limited. To request access, reach out to your account manager.

<br />

The AdChoices custom view feature lets you position the AdChoices icon in a
custom location. This is different from AdChoices position controls, which only
allows specification of one of the four corners.

Set the [`GADNativeAd.adChoicesView`](https://developers.google.com/admob/ios/api/reference/Classes/GADNativeAd.md.txt)
property with a [`GADAdChoicesView`](https://developers.google.com/admob/ios/api/reference/Classes.md.txt#gadadchoicesview)
prior to rendering and the AdChoices content renders inside the
`GADAdChoicesView`.

The following example demonstrates how to set a custom AdChoices view. The
AdChoices icon renders inside the `GADAdChoicesView`:

### Swift

```swift
private func createAdChoicesView(nativeAdView: NativeAdView) {
  // Define a custom position for the AdChoices icon.
  let customRect = CGRect(x: 100, y: 100, width: 15, height: 15)
  let customAdChoicesView = AdChoicesView(frame: customRect)
  nativeAdView.addSubview(customAdChoicesView)
  nativeAdView.adChoicesView = customAdChoicesView
}
```

### Objective-C

```objective-c
- (void)createAdChoicesViewWithNativeAdView:(GADNativeAdView *)nativeAdView {
  // Define a custom position for the AdChoices icon.
  CGRect customRect = CGRectMake(100, 100, 15, 15);
  GADAdChoicesView *customAdChoicesView = [[GADAdChoicesView alloc] initWithFrame:customRect];
  [nativeAdView addSubview:customAdChoicesView];
  nativeAdView.adChoicesView = customAdChoicesView;
}
```

## Video controls

This section details how customize the playback experience for video ads. You
have the option to set the initial mute state and implement custom playback
controls.

### Start mute behavior

The start muted behavior lets you disable or enable a video's starting audio.

Set [`GADVideoOptions startMuted`](https://developers.google.com/admob/ios/api/reference/Classes/GADVideoOptions.md.txt#startmuted)
with a `BOOL` value.

- The start muted behavior is enabled by default.

- When disabled, your app requests the video should begin with
  audio.

- When enabled, your app requests that the video should begin with audio muted.

The following example shows how to start the video with un-muted audio.

<br />

### Swift

```swift
let videoOptions = VideoOptions()
videoOptions.shouldStartMuted = false

adLoader = AdLoader(
  adUnitID: "nativeAdUnitID",
  rootViewController: self,
  adTypes: [.native],
  options: [videoOptions])
```

### Objective-C

```objective-c
GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
videoOptions.startMuted = NO;

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"nativeAdUnitID"
                                   rootViewController:self
                                              adTypes:@[ GADAdLoaderAdTypeNative ]
                                              options:@[ videoOptions ]];
```

### Custom playback controls


> [!WARNING]
> Warning: Access to this feature is limited. To request access, reach out to your account manager.

<br />

This lets you request custom video input controls to play, pause, or mute the
video.

Set [`GADVideoOptions customControlsRequested`](https://developers.google.com/admob/ios/api/reference/Classes/GADVideoOptions.md.txt#customcontrolsrequested)
with a `BOOL` value.

- Custom playback control are disabled by default.

- When disabled, your video will show SDK rendered input controls.

<!-- -->

- When enabled you can then use [`GADVideoController play`](https://developers.google.com/admob/ios/api/reference/Classes/GADVideoController.md.txt#-play) , [`GADVideoController pause`](https://developers.google.com/admob/ios/api/reference/Classes/GADVideoController.md.txt#-pause) , and [`GADVideoController setMute`](https://developers.google.com/admob/ios/api/reference/Classes/GADVideoController.md.txt#-setmute:) to control the video ad.

If the ad does have video content and custom controls are enabled, you should
then display your custom controls along with the ad, as the ad won't show any
controls itself. The controls can then call the relevant methods on the

[`GADVideoController`](https://developers.google.com/admob/ios/api/reference/Classes/GADVideoController.md.txt).

The following example shows how request a video with custom playback controls.

<br />

### Swift

```swift
let videoOptions = VideoOptions()
videoOptions.areCustomControlsRequested = true

adLoader = AdLoader(
  adUnitID: "nativeAdUnitID",
  rootViewController: self,
  adTypes: [.native],
  options: [videoOptions])
```

### Objective-C

```objective-c
GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
videoOptions.customControlsRequested = YES;

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"nativeAdUnitID"
                                   rootViewController:self
                                              adTypes:@[ GADAdLoaderAdTypeNative ]
                                              options:@[ videoOptions ]];
```

#### Check if custom controls are enabled

Because it's not known at request time whether the returned ad will allow
custom video controls, you must check whether it has custom controls enabled.

<br />

### Swift

```swift
private func checkCustomControlsEnabled(nativeAd: NativeAd) -> Bool {
  let videoController = nativeAd.mediaContent.videoController
  return videoController.areCustomControlsEnabled
}
```

### Objective-C

```objective-c
- (BOOL)checkCustomControlsEnabledWithNativeAd:(GADNativeAd *)nativeAd {
  GADVideoController *videoController = nativeAd.mediaContent.videoController;
  return videoController.customControlsEnabled;
}
```

#### Render custom video controls

Render custom video controls using the following best practices:

1. Render the custom controls view as a child of the native ad view. This approach lets open measurement viewability calculations consider the custom controls as a friendly obstruction.
2. Avoid rendering an invisible overlay over the entire media view. Overlays block clicks on the media view, negatively impacting native ads performance. Instead, create a small overlay that is just large enough to fit the controls.

> [!NOTE]
> **Note:** For information on measurement and verification providers that have committed to the development of the open measurement viewability standard, see the [Open Measurement Working Group](https://iabtechlab.com/working-groups/open-measurement-working-group/).

## Custom click gestures


> [!WARNING]
> Warning: Access to this feature is limited. To request access, reach out to your account manager.

<br />

Custom click gestures is a native ads feature that lets you register swipes
on ad views as ad clicks. It works with apps that use swipe gestures for
content navigation. This guide shows you how to enable custom click gestures
on your native ads.

<br />

Initialize a [`GADNativeAdCustomClickGestureOptions`](https://developers.google.com/admob/ios/api/reference/Classes/GADNativeAdCustomClickGestureOptions.md.txt)
instance with your selected swipe direction. You also need to indicate whether
to allow taps as clicks.

- Custom click gestures are disabled by default.

- When disabled, only taps count as clicks.

- When enabled, swipe gestures count as clicks, and you can specify whether
  taps still count as clicks.

The following example shows you how to implement a custom swipe gesture to the
right and preserves normal tap behavior.

### Swift

```swift
let swipeGestureOptions = NativeAdCustomClickGestureOptions(
  swipeGestureDirection: .right,
  tapsAllowed: true)

adLoader = AdLoader(
  adUnitID: "nativeAdUnitID",
  rootViewController: self,
  adTypes: [.native],
  options: [swipeGestureOptions])
```

### Objective-C

```objective-c
GADNativeAdCustomClickGestureOptions *swipeGestureOptions =
    [[GADNativeAdCustomClickGestureOptions alloc]
        initWithSwipeGestureDirection:UISwipeGestureRecognizerDirectionRight
                          tapsAllowed:YES];

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"nativeAdUnitID"
                                   rootViewController:self
                                              adTypes:@[ GADAdLoaderAdTypeNative ]
                                              options:@[ swipeGestureOptions ]];
```

> [!WARNING]
> **Warning:** If your account doesn't have custom click gestures enabled, ad requests return a no-fill.

#### Listen for swipe gesture events

<br />

When a swipe gesture click is recorded, Google Mobile Ads SDK invokes the
[`nativeAdDidRecordSwipeGestureClick:`](https://developers.google.com/admob/ios/api/reference/Protocols/GADNativeAdDelegate.md.txt#-nativeaddidrecordswipegestureclick:)
delegate method on [`GADNativeAdDelegate`](https://developers.google.com/admob/ios/api/reference/Protocols/GADNativeAdDelegate.md.txt)
, in addition to the existing [`nativeAdDidRecordClick:`](https://developers.google.com/admob/ios/api/reference/Protocols/GADNativeAdDelegate.md.txt#-nativeaddidrecordclick:)
delegate method.

### Swift

```swift
// Called when a swipe gesture click is recorded, as configured in
// NativeAdCustomClickGestureOptions.
func nativeAdDidRecordSwipeGestureClick(_ nativeAd: NativeAd) {
  print("A swipe gesture click has occurred.")
}

// Called when a swipe gesture click or a tap click is recorded.
func nativeAdDidRecordClick(_ nativeAd: NativeAd) {
  print("A swipe gesture click or tap click has occurred.")
}
```

### Objective-C

```objective-c
// Called when a swipe gesture click is recorded, as configured in
// GADNativeAdCustomClickGestureOptions.
- (void)nativeAdDidRecordSwipeGestureClick:(GADNativeAd *)nativeAd {
  NSLog(@"A swipe gesture click has occurred.");
}

// Called when a swipe gesture click or a tap click is recorded.
- (void)nativeAdDidRecordClick:(GADNativeAd *)nativeAd {
  NSLog(@"A swipe gesture click or tap click has occurred.");
}
```

#### Mediation

Custom click gestures only work on native ads that Google Mobile
Ads SDK renders. Ad sources that
[require third-party SDKs](https://developers.google.com/admob/ios/choose-networks.md.txt) for
rendering, don't respond to the custom click directions setting.