Skip to main content

Banner Ads

Implementing View Controller

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

  • add these properties

    GFPAdLoader *adLoader

    GFPBannerView *bannerView

  • and implement these delegate protocols

    GFPAdLoaderDelegate

    GFPBannerViewDelegate

info

GFPAdLoaderDelegate delivers banner and native view if ad response is successful.

GFPBannerViewDelegate delivers banner view's impression, click, size changes, errors, etc.

// MyViewController.h

@import GFPSDK;

@interface MyViewController : UIViewController <GFPAdLoaderDelegate, GFPBannerViewDelegate>

@property (nonatomic) GFPAdLoader *adLoader;
@property (nonatomic) GFPBannerView *bannerView;

@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.
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:@"UnitId"
rootViewController:self
adParam:adParam];

GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluidWidth;
[self.adLoader setBannerDelegate:self bannerOptions:bannerOptions];

// Requesting Ad
self.adLoader.delegate = self;
[self.adLoader loadAd];
}

Additional Configurations

GFPRenderDisplayAgentType

GFPRenderDisplayAgentType decides default behavior for landing on ad link. The default is GFPDisplayAgentTypeInApp

  • GFPDisplayAgentTypeInApp: opens in-app browser
  • GFPDisplayAgentTypeScheme: opens by app scheme
  • GFPDisplayAgentTypeNativeSafari: opens on safari
// Safari
GFPRenderDisplayAgent *displayAgent = [[GFPRenderDisplayAgent alloc] initWithType: GFPDisplayAgentTypeNativeSafari];
[GFPAdManager adConfiguration].displayAgent = displayAgent;

// App scheme
GFPRenderDisplayAgent *displayAgent = [[GFPRenderDisplayAgent alloc] initWithType: GFPDisplayAgentTypeScheme scheme: @"AppScheme"];
[GFPAdManager adConfiguration].displayAgent = displayAgent;

Ad Requset Timeout

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

self.adLoader.requestTimeoutInterval = ...

Loading Native Ad Simultaneously

Load either banner or native ad on single ad request.

  • Configure native ad request options along with banner ad on single GFPAdLoader as in code example.

  • GFPAdLoaderDelegate will call either adLoader:didReceiveNativeAd: or adLoader:didReceiveNativeSimpleAd: on ad response success.

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

GFPAdNativeSimpleOptions *nativeSimpleOptions = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOptions.simpleAdRenderingSetting = ...;
[self.adLoader setNativeSimpleDelegate:self nativeSimpleOptions:nativeSimpleOptions];

self.adLoader.delegate = self;
[self.adLoader loadAd];

Configure GFPBannerViewLayoutType on GFPAdBannerOptions. Default is GFPBannerViewLayoutTypeFixed

info
  • In most cases, GFPBannerViewLayoutTypeFixed or GFPBannerViewLayoutTypeFluidWidth is recommended.

  • Innate banner size can be found in GFPBannerView.adSize

Fixed Layout

Banner content gets its size fixed regardless of its containing view.

GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFixed;
Fluid Width Layout

You can set banner content's width manually.

GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluidWidth;
  • Request ad with fluid width banner options, than configure width of the GFPBannerView by the desired size.
self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.bannerView.widthAnchor constraintEqualToConstant:SUPERVIEW_SIZE.width].active = YES;
CGRect frame = CGRectMake(x, y, width, height);
[self.bannerView setFrame: frame];
danger

The received banner ad should innately support fluid width layout,

GFPBannerView will draw background on the sides if it doesn't.

Fluid Height Layout

You can set banner content's height manually.

GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluidHeight;
Fluid Layout

You can set banner content's width & height manually.

GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluid;

Requesting with Host Meta Data

You can send hostMeta with ad request, which is data discussed between the publisher and advertiser.

  • You can send device's interface style. It is prioritized over the global setting, interface style.
//example
GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.hostMeta = [NSDictionary dictionaryWithObjectsAndKeys:@"light", @"theme", nil];
bannerOptions.hostMeta = [NSDictionary dictionaryWithObjectsAndKeys:@"dark", @"theme", nil];
bannerOptions.hostMeta = [NSDictionary dictionaryWithObjectsAndKeys:@"system", @"theme", nil];

GFPAdLoaderDelegate

On Ad Load Success

- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveBannerAd:(GFPBannerView *)bannerView {
[self.view addSubview:bannerView];
// Than set view's layout on the superview.
// ...
}

On Ad Load Failure

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

On Native Ad Load Success

For GFPAdLoader.nativeSimpleOption or GFPAdLoader.nativeOption set, implement these delegate methods.

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

- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd {
// ...
}

GFPBannerViewDelegate

GFPBannerViewDelegate delivers banner view's impression, click, size changes, errors, etc.

See more information in GFPBannerViewDelegate.h

On Banner View Unload

- (void)bannerShouldUnload:(GFPBannerView *)bannerView{
// ...
}
info

Notes on implementing bannerShouldUnload: with MRAID 3.0

For MRAID >= 3.0, GFPBannerView automatically unloads from superview after calling bannerShouldUnload:

On Banner View Impression

- (void)bannerAdWasSeen:(GFPBannerView *)bannerView {
...
}

On Banner Clicked

- (void)bannerAdWasClicked:(GFPBannerView *)bannerView {
...
}

On Banner Size Change

bannerView:didChangeWith: is called when banner content size changes.

See more information in GFPBannerAdSize.h

This method must be implemented if GFPBannerSizeType is set to fluid types.

  • For .fluidWidth, size.width is returned as -1. Manually set width to desired value.

  • For .fluidHeight, size.height is returned as -1. Manaully set height to desired value.

  • For .fluid, manually set width & height to desired value.

- (void)bannerView:(GFPBannerView *)bannerView didChangeWith:(GFPBannerAdSize *)size {
...
}

On Ad Meta Data Change

- (void)bannerView:(GFPBannerView *)bannerView didChangeAdMeta:(NSDictionary <NSString *, NSString *>*)adMeta {
...
//adMeta example: { 'bgcolor':'#000000', 'fontcolor':'#FFFFFF' };
}

On User Muting Ad

"Ad Mute" button on a corner of the ad, providing users options to hide unwanted ads.

On muted, banner view will show "Ad is blocked. NAVER will not show this ad again." message instead of ad. Than it is app's choice whether to completely remove the banner view using this delegate method.

- (void)bannerAdWasMuted:(GFPBannerView *)bannerView {

}