Skip to main content

Native Normal Ad

Native Normal Ads are standardized native ad that consists of tweakable components, such as title, body, cta, icon, media, etc.

Implementing View Controller

In the view controller that will present the ad view as subview,

  • add these properties

    GFPAdLoader *adLoader

    GFPNativeAd *nativeView

  • and implement these delegate protocols

    GFPAdLoaderDelegate

    GFPNativeAdDelegate

// MyViewController.h

@import GFPSDK;

@interface MyViewController : UIViewController <GFPAdLoaderDelegate, GFPNativeAdDelegate>

@property (nonatomic) GFPAdLoader *adLoader;

@property (nonatomic) GFPNativeAd *nativeAd;
@property (nonatomic) GFPNativeAdView *nativeAdView;

@end

GFPAdLoader

Initialize GFPAdLoader in your view controller, say, in viewDidLoad: and request an ad.

  • Provider GFPAdLoader with Ad Unit ID (essential) as registered on GFP dashboard, and GFPAdParam (optional) for better ad performance.

  • Set GFPAdLoaderDelegate on GFPAdLoader.

danger

Do not use GFPAdLoader instance for multiple ad requests, since it's only designed for single ad request.

- (void)viewDidLoad {
[super viewDidLoad];

GFPAdParam *adParam = [[GFPAdParam alloc]init];
adParam.yearOfBirth = 1990;
adParam.gender = GFPAdParamGenderTypeMale;
...

self.adLoader = [[GFPAdLoader alloc] initWithUnitID:self.unitID
rootViewController:self
adParam:adParam];

GFPAdNativeOptions *nativeOptions = [[GFPAdNativeOptions alloc] init];
nativeOptions.renderingSetting = ...;
[self.adLoader setNativeDelegate:self nativeOptions:nativeOptions];

// Requesting Ad
self.adLoader.delegate = self;
[self.adLoader loadAd];
}
info
  • If you are contracted to use the Communication Ad, provider GFPContentInfo in GFPAdParam
GFPContentInfo *contentInfo = [[GFPContentInfo alloc] initWithSourceType:@"0001" subtype:@"menu" sourceId:@"30907206:7"];
adParam.contentInfo = contentInfo;

Additional Configurations

Ad Requset Timeout

Set timeout (seconds) for ad requests. GFPAdLoaderDelegate will call adLoader:didFailWithError:responseInfo: on timeout. Default is 60 seconds.

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.

GFPNativeAdRenderingSetting *setting = [GFPNativeAdRenderingSetting alloc] init];
setting.preferredAdChoicesViewPosition = GFPAdChoicesViewPositionTopRightCorner;

GFPAdNativeOptions *nativeOptions = [[GFPAdNativeOptions alloc] init];
nativeOptions.renderingSetting = setting;
info

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.

danger

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.

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

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;

Implementing Interface Builder

GFPNativeAd requires to be subclassed by an interface builder view. Create an .xib file with a view and subclass GFPNativeAdView and its subviews.

  1. In your .xib file, open Identity Inspector tab on Xcode, than set Custom Class to GFPNativeAdView. 예시이미지

  2. Add subviews that corresponds to title label, body label, etc. onto the GFPNativeAdView and connect them to outlets on the Connections Inspector tab.

  3. Add another subview than set its custom class as GFPMediaView. 예시이미지

danger

Do not allocate more than one GFPNativeAdView for one GFPNativeAd.

GFPAdLoaderDelegate

On Ad Load Success

- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeAd:(GFPNativeAd *)nativeAd {
...
}

On Ad Load Failure

- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didFailWithError:(GFPError *)error responseInfo:(GFPLoadResponseInfo *)responseInfo {
...
}

Copying Text Contents

On receiving a GFPNativeAd, it is necessary to copy the text contents into the text label subviews.


- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeAd:(GFPNativeAd *)nativeAd {
// Set `GFPNativeAdDelegate`
self.nativeAd = nativeAd;
self.nativeAd.delegate = self;

// Copy text contents to subviews
self.nativeAdView.titleLabel.text = nativeAd.title;
self.nativeAdView.bodyLabel.text = nativeAd.body;
self.nativeAdView.advertiserLabel.text = nativeAd.advertiser;
selt.nativeAdView.callToActionLabel.text = nativeAd.callToAction;
...

// As soon as assigning a `GFPNativeAd` to the `GFPNativeAdView`, it starts tracking impressions, and rendering iconView and mediaView images.
self.nativeAdView.nativeAd = nativeAd;

// Add as subview
[self.view addSubView:self.nativeAdView];
}

GFPNativeAdDelegate

On view impression

- (void)nativeAdWasSeen:(GFPNativeAd *)nativeAd {
...
}

On Click

- (void)nativeAdWasClicked:(GFPNativeAd *)nativeAd {
...
}

On Render Error

- (void)nativeAd:(GFPNativeAd *)nativeAd didFailWithError:(GFPError *)error {
...
}

Auxiliary

Rendering Native Ad Using Extrnal Ad Network SDKs

  • Get the original native components from the external ad network SDKs in the GFPNativeAd's adProviderNativeAd property.

  • Get the name of ad network by the GFPNativeAd's adProviderType property.

Than typecast the adProviderNativeAd to the original SDK's native ad type.

@import FBAudienceNetwork;    // FAN SDK
@import GoogleMobileAds; // DFP SDK

- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeAd:(GFPNativeAd *)nativeAd {

self.nativeAd = nativeAd;
self.nativeAd.delegate = self;

if (_nativeAd.adProviderType == GFPNativeAdProviderTypeFAN) {
// Handle FAN native ad
...
} else if (gfpNativeAd.adProviderType == GFPNativeAdProviderTypeDFP) {
// Handle DFP native ad
...
}

}