Skip to main content

Getting Started

Banner ads are rectangular image-based ads displayed within your app's layout, implemented as a WebView-based ad format.

Sample Image

Prerequisites

NAMSDK Import

Import the SDK module.

import GFPSDK

With the banner ad provider's Pod added to your project, initialize via GFPAdManager. (Performed only once when the app launches.)

Provider OptionAd ProviderCocoaPods
GFPBannerProviderOptionNDANaver NDApod 'GFPSDK/MediationNDA'
GFPBannerProviderOptionDFPGoogle GAM (Google Ad Manager)pod 'GFPSDKMediationDFP'
GFPBannerProviderOptionInMobiInMobipod 'GFPSDKMediationInMobi'
GFPBannerProviderOptionFANMeta Audience Networkpod 'GFPSDKMediationFAN'
GFPBannerProviderOptionUnityUnity Adspod 'GFPSDKMediationUnity'
GFPBannerProviderOptionAppLovinAppLovin MAXpod 'GFPSDKMediationAppLovin'
GFPBannerProviderOptionVungleLiftoff (Vungle)pod 'GFPSDKMediationVungle'
GFPBannerProviderOptionDTDigital Turbinepod 'GFPSDKMediationDT'
GFPBannerProviderOptionISIronSourcepod 'GFPSDKMediationIronSource'
GFPBannerProviderOptionAPSAmazon Publisher Servicespod 'GFPSDKMediationAPS'
GFPBannerProviderOptionChartBoostChartboostpod 'GFPSDKMediationChartBoost'
GFPBannerProviderOptionBidMachineBidMachinepod 'GFPSDKMediationBidMachine'
GFPBannerProviderOptionPanglePanglepod 'GFPSDKMediationPangle'
// Add cocoapods dependency if you want to integrate DFP, NDA, Inmobi, Facebook banner ads.
GFPAdManager.setup(withPublisherCd: "publisherCd") { (error : GFPError?) in
print("Setup Eror: \(String(describing: error?.description))")
}
tip

For detailed GFPAdManager configuration, refer to Ad Manager Settings.

Writing the View Controller

Create a view controller (MyViewController) and perform the following tasks in the header file (MyViewController.h).

  1. Declare a GFPAdLoader *adLoader property in the view controller.
  2. Implement the GFPAdLoaderDelegate protocol in the view controller.
  3. Declare a GFPBannerView *bannerView property in the view controller.
  4. Implement the GFPBannerViewDelegate protocol in the view controller.
info

GFPAdLoaderDelegate delivers events related to banner (and native) ad loading, while GFPBannerViewDelegate delivers events such as impression, click, and rendering errors for the loaded banner object.

// MyViewController.h
import GFPSDK

class MyViewController : UIViewController, GFPAdLoaderDelegate, GFPBannerViewDelegate {
private var adLoader : GFPAdLoader?
private var bannerView : GFPBannerView?
}

Creating GFPAdLoader and Requesting an Ad

Create an instance of GFPAdLoader in the viewDidLoad method of MyViewController.m, and request an ad.

  • When creating a GFPAdLoader instance, provide your Ad Unit ID along with user information set in GFPAdParam. GFPAdParam is used for targeting to improve ad performance.
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)

self.adLoader?.delegate = self
self.adLoader?.loadAd()
}
tip

When a banner ad request succeeds, the adLoader:didReceiveBannerAd: method of GFPAdLoaderDelegate is called. GFPBannerView is a standard view object (UIView) and can be added to the view hierarchy.

Implementing GFPAdLoaderDelegate

By implementing GFPAdLoaderDelegate, you can receive ad load-related events through the corresponding methods.

Load Success and Failure

On Banner Load Success

When a banner ad loads successfully, display the ad at the desired position and set constraints as needed.

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceiveBannerAd bannerView: GFPBannerView!) {
self.view.addSubview(bannerView)
// Set constraints
...
}

On Load Failure

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didFailWithError error: GFPError!, responseInfo: GFPLoadResponseInfo!) {
// ...
}

On Native Ad Load Success

If nativeSimpleOption or nativeOption is configured on GFPAdLoader, either a banner or native ad may be returned.

Implementing GFPBannerViewDelegate

By implementing GFPBannerViewDelegate, you can receive events through the corresponding methods.

When Unload Is Called from Creative with MRAID 3.0 Applied

This method is called when Unload — a spec added in MRAID 3.0 — is invoked. After this method is called, all internal ad views within GFPBannerView are removed.

func bannerShouldUnload(_ bannerView: GFPBannerView) {
// ...
}

Events Occurring After Load

For details, refer to the GFPBannerViewDelegate.h file.

On Ad Impression

func bannerAdWasSeen(_ bannerView: GFPBannerView) {
...
}

On Ad Rendered

func bannerAdWasRendered(_ bannerView: GFPBannerView) {
...
}

On Ad Clicked

func bannerAdWasClicked(_ bannerView: GFPBannerView) {
...
}

On Ad Size Change

Called when the ad size changes due to the ad creative.

When called, first use GFPBannerSizeType to determine whether the size is Fixed or Fluid. If Fluid, you can change it to the desired size. (Refer to the GFPBannerAdSize.h file)

  • For FluidWidth, size.width = -1, so you need to set the desired Width value.
  • For FluidHeight, size.height = -1, so you need to set the desired Height value.
  • For Fluid, size.width = -1 and size.height = -1, so you need to set the desired Width and Height values.
func bannerView(_ bannerView: GFPBannerView, didChangeWith size: GFPBannerAdSize) {
...
}

On Ad Meta Data Change

Called when the ad meta data changes due to the ad creative.

func bannerView(_ bannerView: GFPBannerView, didChangeAdMeta adMeta: [String : String]) {
...
//adMeta example: ["bgcolor":"#000000", "fontcolor":"#FFFFFF"]
}

On Ad Muted by User

When an ad is muted, the service is notified via callback. After muting, GFPSDK displays a screen showing "This ad will no longer appear." Whether to remove the ad from the screen or keep it displayed is determined by the service's policy.

func bannerAdWasMuted(_ bannerView: GFPBannerView) {

}

In-App Browser Presented / Dismissed Events

Called when the default in-app browser is presented or dismissed after an ad click.

func bannerAdDidPresentDefaultInAppBrowser(_ bannerView: GFPBannerView) {
// In-app browser presented
}

func bannerAdDidDismissDefaultInAppBrowser(_ bannerView: GFPBannerView) {
// In-app browser dismissed
}