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.
- Objective-C
- Swift
@import GFPSDK;
import GFPSDK
Add and initialize dependency
Please refer to getting-started guide.
Create a view controller
Apply following steps on the view controller that will contain ad views.
- Declare the GFPAdLoader *adLoader property in the view controller.
- Implement the GFPAdLoaderDelegate protocol in the view controller.
GFPAdLoaderDelegate transmits events related to native ad loading.
- Declare the GFPBannerView *bannerView property on the view controller.
- Implement the GFPBannerViewDelegate protocol on the view controller.
GFPBannerViewDelegate delivers events such as exposure, click, and rendering errors of the loaded banner object.
- Declare the GFPNativeAd *nativeAd property on the view controller.
- Implement the GFPNativeAdDelegate protocol on the view controller.
GFPNativeAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native objects.
- Declare the GFPNativeAd *nativeAd property in the view controller.
- Implement the GFPNativeAdDelegate protocol in the view controller.
GFPNativeSimpleAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native simple object.
- Objective-C
- Swift
// 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
// MyViewController.h
import GFPSDK
class MyViewController : UIViewController,
GFPAdLoaderDelegate,
GFPBannerViewDelegate,
GFPNativeAdDelegate,
GFPNativeSimpleAdDelegate {
private var adLoader : GFPAdLoader?
private var bannerView : GFPBannerView?
private var nativeSimpleAd : GFPNativeAd?
private var nativeSimpleAdView : GFPNativeAdView?
private var nativeSimpleAd : GFPNativeSimpleAd?
private var nativeSimpleAdView : GFPNativeSimpleAdView?
}
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.
- 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];
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];
}
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)
let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = ...
self.adLoader?.setNativeDelegate(self, nativeOptions: nativeOption)
let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.renderingSetting = ...
self.adLoader?.setNativeSimpleDelegate(self, nativeSimpleOptions: nativeSimpleOption)
self.adLoader?.delegate = self
self.adLoader?.loadAd()
}
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
- For subsequent rendering and operations, please refer to the guide of each advertisement.