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
GFPAdLoaderDelegate
delivers banner and native view if ad response is successful.
GFPBannerViewDelegate
delivers banner view's impression, click, size changes, errors, etc.
- Objective-C
- Swift
// MyViewController.h
@import GFPSDK;
@interface MyViewController : UIViewController <GFPAdLoaderDelegate, GFPBannerViewDelegate>
@property (nonatomic) GFPAdLoader *adLoader;
@property (nonatomic) GFPBannerView *bannerView;
@end
// MyViewController.h
import GFPSDK
class MyViewController : UIViewController, GFPAdLoaderDelegate, GFPBannerViewDelegate {
private var adLoader : GFPAdLoader?
private var bannerView : GFPBannerView?
}
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, andGFPAdParam
(optional) for better ad performance.
Do not use GFPAdLoader
instance for multiple ad requests, since it's only designed for single ad request.
- Objective-C
- Swift
- (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];
}
override func viewDidLoad() {
super.viewDidLoad()
let adParam = GFPAdParam()
adParam.yearOfBirth = 1990
adParam.gender = .male
...
self.adLoader = GFPAdLoader(unitID: "UnitId", rootViewController: self, adParam: adParam)
let bannerOption = GFPAdBannerOptions()
bannerOption.layoutType = .fluidWidth
self.adLoader?.setBannerDelegate(self, bannerOptions: bannerOption)
// 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 browserGFPDisplayAgentTypeScheme
: opens by app schemeGFPDisplayAgentTypeNativeSafari
: opens on safari
- Objective-C
- Swift
// 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;
// Safari
let displayAgent = GFPRenderDisplayAgent(type: .displayAgentTypeNativeSafari)
GFPAdManager.adConfiguration().displayAgent = displayAgent
// App scheme
let displayAgent = GFPRenderDisplayAgent(type: .displayAgentTypeScheme, 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.
- Objective-C
- Swift
self.adLoader.requestTimeoutInterval = ...
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 eitheradLoader:didReceiveNativeAd:
oradLoader:didReceiveNativeSimpleAd:
on ad response success.
- Objective-C
- Swift
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];
let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = ...
self.adLoader?.setNativeDelegate(self, nativeOptions: nativeOption)
let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = ...
self.adLoader?.setNativeSimpleDelegate(self, nativeSimpleOptions: nativeSimpleOption)
self.adLoader?.delegate = self
self.adLoader?.loadAd()
Banner Layout Type
Configure GFPBannerViewLayoutType
on GFPAdBannerOptions
. Default is GFPBannerViewLayoutTypeFixed
-
In most cases,
GFPBannerViewLayoutTypeFixed
orGFPBannerViewLayoutTypeFluidWidth
is recommended. -
Innate banner size can be found in
GFPBannerView.adSize
Fixed Layout
Banner content gets its size fixed regardless of its containing view.
- Objective-C
- Swift
GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFixed;
let bannerOption = GFPAdBannerOptions()
bannerOption.layoutType = GFPBannerViewLayoutType(rawValue: 0)
Fluid Width Layout
You can set banner content's width manually.
- Objective-C
- Swift
GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluidWidth;
let bannerOption = GFPAdBannerOptions()
bannerOption.layoutType = .fluidWidth
- Request ad with fluid width banner options, than configure width of the
GFPBannerView
by the desired size.
- Objective-C
- Swift
self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.bannerView.widthAnchor constraintEqualToConstant:SUPERVIEW_SIZE.width].active = YES;
CGRect frame = CGRectMake(x, y, width, height);
[self.bannerView setFrame: frame];
self.bannerView?.translatesAutoresizingMaskIntoConstraints = false
self.bannerView?.widthAnchor.constraint(equalToConstant: SUPERVIEW_SIZE.width).isActive = true
/*
원하는 가로 크기만큼 bannerView frame 세팅.
*/
let frame = CGRect(x: x, y: y, width: width, height: height)
self.bannerView?.frame = frame
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.
- Objective-C
- Swift
GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluidHeight;
let bannerOption = GFPAdBannerOptions()
bannerOption.layoutType = .fluidHeight
Fluid Layout
You can set banner content's width & height manually.
- Objective-C
- Swift
GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluid;
let bannerOption = GFPAdBannerOptions()
bannerOption.layoutType = .fluid
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.
- Objective-C
- Swift
//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];
//example
let bannerOption = GFPAdBannerOptions()
bannerOption.hostMeta = ["light":"theme"]
bannerOption.hostMeta = ["dark":"theme"]
bannerOption.hostMeta = ["system":"theme"]
GFPAdLoaderDelegate
On Ad Load Success
- Objective-C
- Swift
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveBannerAd:(GFPBannerView *)bannerView {
[self.view addSubview:bannerView];
// Than set view's layout on the superview.
// ...
}
func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceiveBannerAd bannerView: GFPBannerView!) {
self.view.addSubview(bannerView)
// Than set view's layout upon the superview.
...
}
On Ad Load Failure
- Objective-C
- Swift
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didFailWithError:(GFPError *)error responseInfo:(GFPLoadResponseInfo *)responseInfo {
// ...
}
func adLoader(_ unifiedAdLoader: GFPAdLoader!, didFailWithError error: GFPError!, responseInfo: GFPLoadResponseInfo!) {
// ...
}
On Native Ad Load Success
For GFPAdLoader.nativeSimpleOption
or GFPAdLoader.nativeOption
set, implement these delegate methods.
- Objective-C
- Swift
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeAd:(GFPNativeAd *)nativeAd {
// ...
}
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd {
// ...
}
func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceiveNativeAd bannerView: GFPNativeAd!) {
...
}
func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceiveNativeSimpleAd bannerView: GFPNativeSimpleAd!) {
...
}
GFPBannerViewDelegate
GFPBannerViewDelegate
delivers banner view's impression, click, size changes, errors, etc.
See more information in GFPBannerViewDelegate.h
On Banner View Unload
- Objective-C
- Swift
- (void)bannerShouldUnload:(GFPBannerView *)bannerView{
// ...
}
func bannerShouldUnload(_ bannerView: GFPBannerView) {
// ...
}
Notes on implementing bannerShouldUnload: with MRAID 3.0
For MRAID >= 3.0, GFPBannerView automatically unloads from superview after calling bannerShouldUnload:
On Banner View Impression
- Objective-C
- Swift
- (void)bannerAdWasSeen:(GFPBannerView *)bannerView {
...
}
func bannerAdWasSeen(_ bannerView: GFPBannerView) {
...
}
On Banner Clicked
- Objective-C
- Swift
- (void)bannerAdWasClicked:(GFPBannerView *)bannerView {
...
}
func bannerAdWasClicked(_ bannerView: GFPBannerView) {
...
}
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.
- Objective-C
- Swift
- (void)bannerView:(GFPBannerView *)bannerView didChangeWith:(GFPBannerAdSize *)size {
...
}
func bannerView(_ bannerView: GFPBannerView, didChangeWith size: GFPBannerAdSize) {
...
}
On Ad Meta Data Change
- Objective-C
- Swift
- (void)bannerView:(GFPBannerView *)bannerView didChangeAdMeta:(NSDictionary <NSString *, NSString *>*)adMeta {
...
//adMeta example: { 'bgcolor':'#000000', 'fontcolor':'#FFFFFF' };
}
func bannerView(_ bannerView: GFPBannerView, didChangeAdMeta adMeta: [String : String]) {
...
//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.
- Objective-C
- Swift
- (void)bannerAdWasMuted:(GFPBannerView *)bannerView {
}
func bannerAdWasMuted(_ bannerView: GFPBannerView) {
}