The last parameter included in the creation of the GADAdLoader
is an
optional array of objects. This section describes those options.
Swift
adLoader = GADAdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511", rootViewController: self, adTypes: [ ... ad type constants ... ], options: [ ... ad loader options objects ... ])
Objective-C
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511" rootViewController:rootViewController adTypes:@[ ... ad type constants ... ] options:@[ ... ad loader options objects ... ]];
GADNativeAdImageAdLoaderOptions
GADNativeAdImageAdLoaderOptions
contains properties relating to images in native ads. Apps can control how a
GADAdLoader
handles image assets by creating a
GADNativeAdImageAdLoaderOptions
object, setting its properties
(disableImageLoading
,
preferredImageOrientation
,
and
shouldRequestMultipleImages
),
and passing it in during initialization.
GADNativeAdImageAdLoaderOptions
has the following properties:
disableImageLoading
- Image assets for native ads are returned via instances of
GADNativeAdImage
, which containsimage
andimageURL
properties. IfdisableImageLoading
is set tofalse
, which is the default (NO
in Objective-C), the SDK will fetch image assets automatically and populate both theimage
and theimageURL
properties for you. If it's set totrue
(orYES
in Objective-C), the SDK will only populateimageURL
, allowing you to download the actual images at your discretion. Use themainImage
property ofGADMediaContent
to set the image for the media view when manually downloading images. preferredImageOrientation
Some creatives have multiple images available to match different device orientations. Apps can request images for a particular orientation by setting this property to one of the orientation constants:
GADNativeAdImageAdLoaderOptionsOrientationAny
GADNativeAdImageAdLoaderOptionsOrientationLandscape
GADNativeAdImageAdLoaderOptionsOrientationPortrait
If you use
preferredImageOrientation
to specify a preference for landscape or portrait image orientation, the SDK will place images matching that orientation first in image asset arrays and place non-matching images after them. Since some ads will only have one orientation available, publishers should make sure that their apps can handle both landscape and portrait images.If this method is not called, the default value of
GADNativeAdImageAdLoaderOptionsOrientationAny
will be used.
shouldRequestMultipleImages
Some image assets will contain a series of images rather than just one. By setting this value to true, your app indicates that it's prepared to display all the images for any assets that have more than one. By setting it to
false
(the default) your app instructs the SDK to provide just the first image for any assets that contain a series.If no
GADAdLoaderOptions
objects are passed in when initializing aGADAdLoader
, the default value for each option will be used.
GADNativeAdViewAdOptions
GADNativeAdViewAdOptions
objects are used to indicate preferences for how native ad views should
represent ads. They have a single property:
preferredAdChoicesPosition
,
which you can use to specify the location where the AdChoices icon should
be placed. The icon can appear at any corner of the ad, and defaults to
GADAdChoicesPositionTopRightCorner
. The possible values for this property are:
GADAdChoicesPositionTopRightCorner
GADAdChoicesPositionTopLeftCorner
GADAdChoicesPositionBottomRightCorner
GADAdChoicesPositionBottomLeftCorner
Here's an example showing how to place the AdChoices icon in the top left corner of an ad:
Swift
let adViewOptions = GADNativeAdViewAdOptions() adViewOptions.preferredAdChoicesPosition = .topLeftCorner adLoader = GADAdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511", rootViewController: self, adTypes: [ ... ad type constants ... ], options: [ ... ad loader options objects ... ])
Objective-C
GADNativeAdViewAdOptions *adViewOptions = [[GADNativeAdViewAdOptions alloc] init]; adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopLeftCorner; self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511" rootViewController:self adTypes:@[ ... ad type constants ... ] options:@[ ... ad loader options objects ... ]];
GADVideoOptions
GADVideoOptions
objects are used to indicate how native video assets should be displayed.
The startMuted
boolean indicates whether video assets should begin playback in a muted
state. The default value is true
.
Swift
let videoOptions = GADVideoOptions() // Ads start muted by default. Set to false to start video ads with sound. videoOptions.startMuted = false adLoader = GADAdLoader( adUnitID: "ca-app-pub-3940256099942544/3986624511", rootViewController: self, adTypes: [ ... ad type constants ... ], options: [videoOptions])
Objective-C
GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init]; // Ads start muted by default. Set to NO to start video ads with sound. videoOptions.startMuted = NO; self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511" rootViewController:self adTypes:@[ ... ad type constants ... ] options:@[videoOptions]];
GADMultipleAdsAdLoaderOptions
GADMultipleAdsAdLoaderOptions
objects allow publishers to instruct an ad
loader to load multiple ads in a single request. Ads loaded in this way are
guaranteed to be unique. GADMultipleAdsAdLoaderOptions
has a single property,
numberOfAds
, which represents the number of ads the ad loader should attempt
to return for the request. By default this value is one, and it's capped at a
maximum of five (even if an app requests more ads, at most five will be
returned). The actual number of ads returned is not guaranteed, but will be
between zero and numberOfAds
.
GADNativeAdMediaAdLoaderOptions
To use this feature, include the GADNativeAdMediaAdLoaderOptions
class in the
native ad options array in the GADAdLoader
initialization.
GADNativeAdMediaAdLoaderOptions
objects allow you to select media aspect ratio
preferences. The option is applied to both image and video. This class has one
property: mediaAspectRatio
, which you can use to specify the supported media
aspect ratios. The possible values for this property are:
Objective-C | Swift |
---|---|
GADMediaAspectRatioAny
|
.any
|
GADMediaAspectRatioLandscape
|
.landscape
|
GADMediaAspectRatioPortrait
|
.portrait
|
GADMediaAspectRatioSquare
|
.square
|
Setting mediaAspectRatio
to one of these options will cause only ads with
media of the specified aspect ratio to be returned. If this property is not set
explicitly, the value will default to GADMediaAspectRatioUnknown
and no
restrictions on aspect ratios will be applied.