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.
- Swift
- Objective-C
self.adLoader?.requestTimeoutInterval = ...
self.adLoader.requestTimeoutInterval = ...
GFPNativeSimpleAdRenderingSetting
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.
The AdBadge rendering option has been deprecated since NAMSDK 4.3.0. The AD mark is now rendered by internal logic.
- Swift
- Objective-C
let simpleRenderingSetting = GFPNativeSimpleAdRenderingSetting()
simpleRenderingSetting.renderAdBadge = true
let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = simpleRenderingSetting
GFPNativeSimpleAdRenderingSetting *simpleAdRenderingSetting = [[GFPNativeSimpleAdRenderingSetting alloc] init];
simpleAdRenderingSetting.renderAdBadge = YES;
GFPAdNativeSimpleOptions *nativeSimpleOptions = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOptions.simpleAdRenderingSetting = simpleAdRenderingSetting;
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.
- Swift
- Objective-C
let simpleRenderingSetting = GFPNativeSimpleAdRenderingSetting()
simpleRenderingSetting.adChoicesPositionInFullAdView = true
let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = simpleRenderingSetting
GFPNativeSimpleAdRenderingSetting *simpleAdRenderingSetting = [[GFPNativeSimpleAdRenderingSetting alloc] init];
simpleAdRenderingSetting.adChoicesPositionInFullAdView = YES;
GFPAdNativeSimpleOptions *nativeSimpleOptions = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOptions.simpleAdRenderingSetting = simpleAdRenderingSetting;
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.
- Swift
- Objective-C
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
GFPNativeAdRenderingSetting *simpleAdRenderingSetting = [[GFPNativeAdRenderingSetting alloc] init];
simpleAdRenderingSetting.adInterfaceStyle = GFPAdInterfaceStyleLight;
simpleAdRenderingSetting.adInterfaceStyle = GFPAdInterfaceStyleDark;
simpleAdRenderingSetting.adInterfaceStyle = GFPAdInterfaceStyleSystem; // Follows the style set in iPhone settings.
GFPAdNativeSimpleOptions *nativeSimpleOptions = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOptions.simpleAdRenderingSetting = simpleAdRenderingSetting;
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.
- Swift
- Objective-C
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)
GFPBackgroundOptionAttributes *light = [[GFPBackgroundOptionAttributes alloc] init];
light.color = [UIColor colorWithRed: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;
GFPBackgroundOptionAttributes *dark = [[GFPBackgroundOptionAttributes alloc] init];
dark.color = [UIColor colorWithRed: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;
GFPBackgroundOption *bgOption = [[GFPBackgroundOption alloc] initWithLight:light dark:dark];
GFPNativeSimpleAdRenderingSetting *renderingSetting = [[GFPNativeSimpleAdRenderingSetting alloc] init];
renderingSetting.backgroundOption = bgOption;
GFPAdNativeSimpleOptions *nativeSimpleOption = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOption.simpleAdRenderingSetting = renderingSetting;
GFPAdLoader *adLoader = [[GFPAdLoader alloc] init];
[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.
- Swift
- Objective-C
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()
self.adLoader = [[GFPAdLoader alloc] initWithUnitID:self.unitID
rootViewController:self
adParam:adParam];
GFPAdNativeSimpleOptions *nativeSimpleOptions = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOptions.renderingSetting.useLazyMediaLoading = YES;
[self.adLoader setNativeSimpleDelegate:self nativeSimpleOptions:nativeSimpleOptions];
// Request ad
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.
- Swift
- Objective-C
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
}
}
}
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd {
nativeSimpleAd.delegate = self;
self.nativeSimpleAdView.nativeAd = nativeSimpleAd;
if (nativeSimpleAd.mediaLoadingState == GFPNativeAdMediaLoadingStateLoading) {
[self.nativeSimpleAdView.mediaView showPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_media_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
}
}
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.
- Swift
- Objective-C
// 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
}
}
// GFPNativeSimpleAdDelegate
- (void)nativeSimpleAdDidLoadMedia:(GFPNativeSimpleAd *)nativeSimpleAd {
// The SDK removes the placeholder automatically.
}
- (void)nativeSimpleAdDidFailToLoadMedia:(GFPNativeSimpleAd *)nativeSimpleAd {
if (nativeSimpleAd.mediaLoadingState == GFPNativeAdMediaLoadingStateFailed) {
[self.nativeSimpleAdView.mediaView showPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_fallback_media_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
}
}
- (void)nativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd
didChangeMediaAssetLoadingState:(GFPNativeAdMediaLoadingState)state
assetType:(GFPNativeAdMediaAssetType)assetType {
if (assetType == GFPNativeAdMediaAssetTypeMedia && state == GFPNativeAdMediaLoadingStateFailed) {
// Handle media loading failure
}
}