Skip to main content

Native Ad Options

Ad Requset Timeout

Set timeout (seconds) for ad requests. GFPAdLoaderDelegate will call adLoader:didFailWithError:responseInfo: on timeout. Default is 60 seconds.

self.adLoader?.requestTimeoutInterval = ...

GFPNativeAdRenderingSetting

DFP adChoicesView Positions

DFP adChoiceView is located on the top right corner of the ad by default. Customize the location on one of the four corners by setting GFPNativeAdRenderingSetting.preferredAdChoicesViewPosition.

let renderingSetting = GFPNativeAdRenderingSetting()
renderingSetting.preferredAdChoicesViewPosition = .topRightCorner

let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = renderingSetting
info

Manually managing frame of DFP adChoiceView will now work as expected, despite the official guide.

Native Ad Without Media

Native ad without media content consists of only a icon image, title and body texts.

To exclude media view from a native noraml ad, set GFPNativeAdRenderingSetting.hasMediaView to NO.

danger

You should remove the media view as with hadMediaView set to NO. GFP SDK emits error if hasMediaView flag does not match the actual view hierarchy.

let setting = GFPNativeAdRenderingSetting()
setting.hasMediaView = false

let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = setting

Custom AdChoices Icon

AdChoices (or AdMute) icon or button is located on a corner of ad, providing users for options to hide unwanted ad.

The icon's appearance can be customized by setting GFPNativeAdRenderingSetting.adChociesCustomAsset

let customAsset = GFPCustomAsset(bundle: Bundle.main, size: CGSize(width: 42, height: 16), lightModeName: "commAd", darkModeName: "commAd_dark")

let setting = GFPNativeAdRenderingSetting()
setting.adChoicesCustomAsset = customAsset

let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = setting

Lazy Loading for Native Ads

Enabling Lazy Loading

Enable lazy loading on Native ad's rendering settings to receive GFPNativeAd and text assets via GFPAdLoaderDelegate.adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!). Media and icon (and other assets may be included in the future updates) assets will be loaded asynchronously.

self.adLoader = GFPAdLoader(unitID: "UnitId", rootViewController: self, adParam: adParam)

let nativeOption = GFPAdNativeOptions()
nativeOptions.renderingSetting.useLazyMediaLoading = true
self.adLoader?.setNativeDelegate(self, nativeOptions: nativeOption)

self.adLoader?.delegate = self
self.adLoader?.loadAd()

Showing Placeholder While Lazy Loading

Media views are able to show placeholder while lazy loading. Placeholders will are automatically fit to its parent media view's bounds.

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!) {
self.nativeAdView.nativeAd = nativeAd

self.nativeAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}

self.nativeAdView.showIconPlaceholder { imageView in
imageView.image = UIImage(named: "my_icon_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}

Async Media Loading Callbacks

On completing lazy loading all required media, nativeAdDidLoadMediaData(_:) of GFPNativeAdDelegate will be called.

If any of the media asset fails to load, nativeAdDidFail(toLoadMediaData:) will be called.

// GFPNativeAdDelegate
func nativeAdDidLoadMediaData(_ nativeAd: GFPNativeAd) {
self.nativeAdView.removePlaceholders() // Optional for safety.
}

func nativeAdDidFail(toLoadMediaData nativeAd: GFPNativeAd) {
// Example showing new placeholders on failure.
self.nativeAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}

self.nativeAdView.showIconPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_icon_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
}