Native Ad Options
Ad Requset Timeout
Set timeout (seconds) for ad requests. GFPAdLoaderDelegate will call adLoader:didFailWithError:responseInfo: on timeout. Default is 60 seconds.
- Swift
- Objective-C
self.adLoader?.requestTimeoutInterval = ...
self.adLoader.requestTimeoutInterval = ...
GFPNativeAdRenderingSetting
DFP adChoicesView Positions
DFP adChoiceView is located on the top right corner of the ad by default. Customize the location on one of the four corners by setting GFPNativeAdRenderingSetting.preferredAdChoicesViewPosition.
- Swift
- Objective-C
let renderingSetting = GFPNativeAdRenderingSetting()
renderingSetting.preferredAdChoicesViewPosition = .topRightCorner
let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = renderingSetting
GFPNativeAdRenderingSetting *setting = [GFPNativeAdRenderingSetting alloc] init];
setting.preferredAdChoicesViewPosition = GFPAdChoicesViewPositionTopRightCorner;
GFPAdNativeOptions *nativeOptions = [[GFPAdNativeOptions alloc] init];
nativeOptions.renderingSetting = setting;
Manually managing frame of DFP adChoiceView will now work as expected, despite the official guide.
Native Ad Without Media
Native ad without media content consists of only a icon image, title and body texts.
To exclude media view from a native noraml ad, set GFPNativeAdRenderingSetting.hasMediaView to NO.
You should remove the media view as with hadMediaView set to NO. GFP SDK emits error if hasMediaView flag does not match the actual view hierarchy.
- Swift
- Objective-C
let setting = GFPNativeAdRenderingSetting()
setting.hasMediaView = false
let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = setting
GFPNativeAdRenderingSetting *setting = [GFPNativeAdRenderingSetting alloc] init];
setting.hasMediaView = NO;
GFPAdNativeOptions *nativeOptions = [[GFPAdNativeOptions alloc] init];
nativeOptions.renderingSetting = setting;
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
- Swift
- Objective-C
let customAsset = GFPCustomAsset(bundle: Bundle.main, size: CGSize(width: 42, height: 16), lightModeName: "commAd", darkModeName: "commAd_dark")
let setting = GFPNativeAdRenderingSetting()
setting.adChoicesCustomAsset = customAsset
let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = setting
GFPCustomAsset *customAsset = [[GFPCustomAsset alloc] initWith:[NSBundle mainBundle] size:CGSizeMake(44, 16) lightModeName:@"commAd" darkModeName:@"commAd_dark"];
GFPNativeAdRenderingSetting *setting = [GFPNativeAdRenderingSetting alloc] init];
setting.adChoicesCustomAsset = customAsset;
GFPAdNativeOptions *nativeOptions = [[GFPAdNativeOptions alloc] init];
nativeOptions.renderingSetting = setting;
Lazy Loading for Native Ads
Enabling Lazy Loading
Enable lazy loading on Native ad's rendering settings to receive GFPNativeAd and text assets via
GFPAdLoaderDelegate.adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!).
Media and icon (and other assets may be included in the future updates) assets will be loaded asynchronously.
- Swift
- Objective-C
self.adLoader = GFPAdLoader(unitID: "UnitId", rootViewController: self, adParam: adParam)
let nativeOption = GFPAdNativeOptions()
nativeOptions.renderingSetting.useLazyMediaLoading = true
self.adLoader?.setNativeDelegate(self, nativeOptions: nativeOption)
self.adLoader?.delegate = self
self.adLoader?.loadAd()
self.adLoader = [[GFPAdLoader alloc] initWithUnitID:self.unitID
rootViewController:self
adParam:adParam];
GFPAdNativeOptions *nativeOptions = [[GFPAdNativeOptions alloc] init];
nativeOptions.renderingSetting.useLazyMediaLoading = YES;
[self.adLoader setNativeDelegate:self nativeOptions:nativeOptions];s
// 광고 요청
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.
- Swift
- Objective-C
func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!) {
self.nativeAdView.nativeAd = nativeAd
self.nativeAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
self.nativeAdView.showIconPlaceholder { imageView in
imageView.image = UIImage(named: "my_icon_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeAd:(GFPNativeAd *)nativeAd {
self.nativeAdView.nativeAd = nativeAd
[self.nativeAdView.mediaView showPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_media_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
[self.nativeAdView showIconPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_icon_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
}
Async Media Loading Callbacks
On completing lazy loading all required media,
nativeAdDidLoadMediaData(_:)
of
GFPNativeAdDelegate
will be called.
If any of the media asset fails to load,
nativeAdDidFail(toLoadMediaData:)
will be called.
- Swift
- Objective-C
// GFPNativeAdDelegate
func nativeAdDidLoadMediaData(_ nativeAd: GFPNativeAd) {
self.nativeAdView.removePlaceholders() // Optional for safety.
}
func nativeAdDidFail(toLoadMediaData nativeAd: GFPNativeAd) {
// Example showing new placeholders on failure.
self.nativeAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
self.nativeAdView.showIconPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_icon_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
}
// GFPNativeAdDelegate
- (void)nativeAdDidLoadMediaData:(GFPNativeAd *)nativeAd {
[self.nativeAdView removePlaceholders]; // Optional for safety.
}
- (void)nativeAdDidFailToLoadMediaData:(GFPNativeAd *)nativeAd {
// Example showing new placeholders on failure.
[self.nativeAdView.mediaView showPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_fallback_media_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
[self.nativeAdView showIconPlaceholderWith:^(UIImageView *imageView) {
imageView.image = [UIImage imageNamed:@"my_fallback_icon_placeholder"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
}];
}