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 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.
- 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
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.
- Swift
- Objective-C
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
}
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd {
self.nativeSimpleAdView.nativeAd = nativeSimpleAd
[self.nativeSimpleAdView.mediaView showPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_media_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
}
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.
- Swift
- Objective-C
// 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
}
}
// GFPNativeSimpleAdDelegate
- (void)nativeSimpleAdDidLoadMedia:(GFPNativeSimpleAd *)nativeSimpleAd {
[self.nativeSimpleAdView removePlaceholders]; // Optional for safety.
}
- (void)nativeSimpleAdDidFailToLoadMedia:(GFPNativeSimpleAd *)nativeSimpleAd {
// Example showing new placeholders on failure.
[self.nativeSimpleAdView.mediaView showPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_fallback_media_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
}