Skip to main content

Native Simple Ad Options

Ad Request Timeout (Default: 60 seconds)

If no ad response is received within the specified time (in seconds) after the ad request, the existing request is invalidated and the adLoader:didFailWithError:responseInfo: method of GFPAdLoaderDelegate is called.

self.adLoader?.requestTimeoutInterval = ...

GFPNativeSimpleAdRenderingSetting

info

This section covers only the most commonly used key options. For the full list of all options provided by GFPNativeSimpleAdRenderingSetting, refer to Native Rendering Options.

AdBadge Rendering Option

This option controls whether the 'AD' badge is displayed on Native Simple ads. When set to YES, the badge appears at the bottom-right of the image; when set to NO, it is not displayed.

danger

The AdBadge rendering option has been deprecated since NAMSDK 4.3.0. The AD mark is now rendered by internal logic.

let simpleRenderingSetting = GFPNativeSimpleAdRenderingSetting()
simpleRenderingSetting.renderAdBadge = true

let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = simpleRenderingSetting

AdMute Position and Touch Area Option

This option controls the area and touch region of the AdChoices button on Native Simple ads. When set to YES, the AdChoices position reference and touch area are both expanded to the full view. The default value is NO.

let simpleRenderingSetting = GFPNativeSimpleAdRenderingSetting()
simpleRenderingSetting.adChoicesPositionInFullAdView = true

let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = simpleRenderingSetting

Interface Style Setting

Independently from the global InterfaceStyle setting, you can apply individual settings to match icon styles when the UI mode differs on a specific screen. Applied according to the priority order of 'per-ad setting > global setting'; if no per-ad style is set, the global setting is used.

let simpleRenderingSetting = GFPNativeSimpleAdRenderingSetting()
simpleRenderingSetting.adInterfaceStyle = .light
simpleRenderingSetting.adInterfaceStyle = .dark
simpleRenderingSetting.adInterfaceStyle = .system // Follows the style set in iPhone settings.

let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = simpleRenderingSetting

NS Custom Background Setting

NS Ad Background Style Setting

This option allows you to set a custom background style when the Native Simple ad design has no background information defined.

let light = GFPBackgroundOptionAttributes()
light.color = UIColor(red: 237/255.0, green: 240/255.0, blue: 244/255.0, alpha: 1.0)
light.alpha = 0.74
light.cornerRadius = 8
light.leftMargin = 8
light.rightMargin = 8
light.bottomMargin = 0
light.topMargin = 0
light.maxWidth = 414
let dark = GFPBackgroundOptionAttributes()
dark.color = UIColor(red: 237/255.0, green: 240/255.0, blue: 244/255.0, alpha: 1.0)
dark.alpha = 0.74
dark.cornerRadius = 8
dark.leftMargin = 8
dark.rightMargin = 8
dark.bottomMargin = 0
dark.topMargin = 0
dark.maxWidth = 414
let bgOption = GFPBackgroundOption(light: light, dark: dark)
let renderingSetting = GFPNativeSimpleAdRenderingSetting()
renderingSetting.backgroundOption = bgOption
let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = renderingSetting
let adLoader = GFPAdLoader()
adLoader.setNativeSimpleDelegate(self, nativeSimpleOptions: nativeSimpleOption)

Lazy Loading for Native Simple Ads

Enabling Lazy Loading

When lazy loading is enabled in the native simple rendering options, the native ad view object is first delivered via GFPAdLoaderDelegate.adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeSimpleAd: GFPNativeSimpleAd!), and the media view image is 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 a Placeholder

You can display a placeholder while media is loading asynchronously. The placeholder appears directly on the ad view and is automatically scaled to fit the view element.

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

When asynchronous loading of all media, including the media view and icon view, completes, nativeSimpleAdDidLoadMedia(_:) of GFPNativeSimpleAdDelegate is called.

If any single item fails to load, nativeSimpleAdDidFail(toLoadMedia:) is 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
}
}