Skip to main content

Native Simple 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 = ...

Interface Style

Configure interface style to customize icon's appearance.

This setting overrides Global Interface Style Setting. Use this setting to alter the appearance in certain contexts.

let simpleRenderingSetting = GFPNativeSimpleAdRenderingSetting()
simpleRenderingSetting.adInterfaceStyle = .light
simpleRenderingSetting.adInterfaceStyle = .dark
simpleRenderingSetting.adInterfaceStyle = .system

let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = simpleRenderingSetting

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 simpleRenderingSetting = GFPNativeSimpleAdRenderingSetting()
simpleRenderingSetting.adChoicesCustomAsset = customAsset

let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = simpleRenderingSetting

Lazy Loading for Native Simple Ads

Enabling Lazy Loading

Enable lazy loading on Native Simple ad's rendering settings to receive GFPNativeSimpleAd and text assets via GFPAdLoaderDelegate.adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeSimpleAd: GFPNativeSimpleAd!). Media view's asset will be loaded asynchronously.

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

let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.renderingSetting.useLazyMediaLoading = true
self.adLoader?.setNativeSimpleDelegate(self, nativeSimpleOptions: nativeSimpleOption)

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 nativeAdSimpleAd: GFPNativeSimpleAd!) {
self.nativeSimpleAdView.nativeAd = nativeSimpleAd

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

Async Media Loading Callbacks

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

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

// GFPNativeSimpleAdDelegate
func nativeSimpleAdDidLoadMedia(_ nativeSimpleAd: GFPNativeSimpleAd) {
self.nativeSimpleAdView.removePlaceholders() // Optional for safety.
}

func nativeSimpleAdDidFail(toLoadMedia nativeSimpleAd: GFPNativeSimpleAd) {
// Example showing new placeholders on failure.
self.nativeSimpleAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
}