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 you enable useLazyMediaLoading in the native simple rendering options, the ad load callback fires first and the media view's image loads asynchronously afterward.

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

Show the placeholder only after you set nativeSimpleAdView.nativeAd = nativeSimpleAd. By then the media view has its final size and position, so the placeholder fits the view.

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeSimpleAd: GFPNativeSimpleAd!) {
nativeSimpleAd.delegate = self
nativeSimpleAdView.nativeAd = nativeSimpleAd

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

Removing Placeholders

Once the media loads successfully, the SDK removes the placeholder for you, so you usually don't need to call removePlaceholders() yourself.

If media loading fails, the SDK leaves the placeholder in place. To show a failure state, set a new placeholder in nativeSimpleAdDidFail(toLoadMedia:) (nativeSimpleAdDidFailToLoadMedia:), or call removePlaceholders() yourself.

To run a custom effect such as a fade-out before the placeholder disappears, set placeholderWillRemoveHandler. The placeholder isn't removed until you call removeHandler, so call it once your animation finishes.

When you reuse table or collection cells, call removePlaceholders() at a reset point such as prepareForReuse so a previous ad's placeholder doesn't linger.

Async Media Loading Callbacks

Once the media view finishes loading successfully, GFPNativeSimpleAdDelegate's nativeSimpleAdDidLoadMedia(_:) is called.

If loading fails, nativeSimpleAdDidFail(toLoadMedia:) is called. The SDK doesn't clear placeholders on failure, so set a failure-state placeholder or remove it yourself.

You can also track media asset state changes through the nativeSimpleAd(_:didChangeMediaAssetLoadingState:assetType:) callback or the mediaLoadingState property.

// GFPNativeSimpleAdDelegate
func nativeSimpleAdDidLoadMedia(_ nativeSimpleAd: GFPNativeSimpleAd) {
// The SDK removes the placeholder automatically.
}

func nativeSimpleAdDidFail(toLoadMedia nativeSimpleAd: GFPNativeSimpleAd) {
if nativeSimpleAd.mediaLoadingState == .failed {
nativeSimpleAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
}
}

func nativeSimpleAd(_ nativeSimpleAd: GFPNativeSimpleAd,
didChangeMediaAssetLoadingState state: GFPNativeAdMediaLoadingState,
assetType: GFPNativeAdMediaAssetType) {
if assetType == .media, state == .failed {
// Handle media loading failure
}
}