Skip to main content

Combining Banner and Native Ads

The GFP SDK provides a way to simultaneously receive banner, native, and native simple advertisements via the GFPAdLoader. Since multiple types are supported on a single page, ad unit settings are required. Discussion with a GFP representative may be required.

GFPSDK Import

Import the GFPSDK module.

@import GFPSDK;

Add and initialize dependency

Please refer to getting-started guide.

Create a view controller

뷰 컨트롤러(MyViewController)를 만들고, 헤더파일(MyViewController.h)에 아래 작업을 수행합니다.

  1. Declare the GFPAdLoader *adLoader property in the view controller.
  2. Implement the GFPAdLoaderDelegate protocol in the view controller.
info

GFPAdLoaderDelegate transmits events related to native ad loading.

  1. Declare the GFPBannerView *bannerView property on the view controller.
  2. Implement the GFPBannerViewDelegate protocol on the view controller.
info

GFPBannerViewDelegate delivers events such as exposure, click, and rendering errors of the loaded banner object.

  1. Declare the GFPNativeAd *nativeAd property on the view controller.
  2. Implement the GFPNativeAdDelegate protocol on the view controller.
info

GFPNativeAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native objects.

  1. Declare the GFPNativeAd *nativeAd property in the view controller.
  2. Implement the GFPNativeAdDelegate protocol in the view controller.

GFPNativeSimpleAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native simple object.

// MyViewController.h

@import GFPSDK;

@interface MyViewController : UIViewController <GFPAdLoaderDelegate,
GFPBannerViewDelegate,
GFPNativeAdDelegate,
GFPNativeSimpleAdDelegate>

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

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

@property (nonatomic) GFPNativeSimpleAd *nativeSimpleAd;
@property (nonatomic) GFPNativeSimpleAdView *nativeSimpleAdView;
@end

Create GFPAdLoader and request advertisement

Create a GFPAdLoader instance from the viewDidLoad method of MyViewController.m and request an advertisement.

  • When creating a GFPAdLoader instance, set the user information in GFPAdParam including the issued advertising unit ID. GFPAdParam is used for targeting to increase ad effectiveness.

  • Set Option and Delegate in GFPAdLoader for the advertisements to be used.

- (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];

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];
}
info

In the case of MoPub, if rootViewController is nil, the internal setting is set to UIApplication.sharedApplication.delegate.window.rootViewController.

Receive GFPAdLoader ad-loading events

  • The combined ads receive Delegate events associated with each ad type. The list of events received is listed below.
    • When the Banner ad response is successful, the adLoader:didReceiveBannerAd: method of GFPAdLoaderDelegate is called. Since GFPBannerView is a regular view object (UIView), it could be included in the view hierarchy.
    • When the Native general ad response is successful, the adLoader:didReceiveNativeAd: method of GFPAdLoaderDelegate is called.
    • When the Native simple ad response is successful, the adLoader:didReceiveNativeSimpleAd: method of GFPAdLoaderDelegate is called.
    • When the ad response fails, the adLoader:didFailWithError:responseInfo: method of GFPAdLoaderDelegate is called.

Event reception and rendering guide after GFPAdLoader