Skip to main content

Getting Started

Native Simple ads are a type of native ad that displays a single standalone image.

NAMSDK Import

Import the SDK module.

import GFPSDK

Initializing the Native Ad Provider

Initialize via GFPAdManager after adding the Pod for the native ad provider you want to integrate to your project. (Perform only once when the app starts.)

Provider OptionAd ProviderCocoaPods
GFPNativeProviderOptionNDANaver NDApod 'GFPSDK/MediationNDA'
GFPNativeProviderOptionLANLINE Ads Networkpod 'GFPSDKMediationLAN'
// DFP, NDA, Inmobi, Facebook 광고를 연동하려는 경우 cocoapods 의존성 추가.
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 steps in the header file (MyViewController.h).
(In this example, a single view controller implements all event protocols.)

  1. Declare a GFPAdLoader *adLoader property on the view controller.
  2. Implement the GFPAdLoaderDelegate protocol on the view controller.
  3. Declare a GFPNativeSimpleAd *nativeSimpleAd property on the view controller.
  4. Implement the GFPNativeSimpleAdDelegate protocol on the view controller.

GFPAdLoaderDelegate delivers events related to native (and banner) ad loading, while GFPNativeSimpleAdDelegate delivers events such as impressions, clicks, and rendering errors for the loaded native ad object.

// MyViewController.h
import GFPSDK

class MyViewController : UIViewController, GFPAdLoaderDelegate, GFPNativeSimpleAdDelegate {
private var adLoader : GFPAdLoader?

private var nativeSimpleAd : GFPNativeSimpleAd?
private var nativeSimpleAdView : GFPNativeSimpleAdView?
}

Creating GFPAdLoader and Requesting an Ad

In the viewDidLoad method of MyViewController.m, create an instance of GFPAdLoader and request an ad.

  • When creating a GFPAdLoader instance, set user information in GFPAdParam along with your issued ad unit ID. 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 nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.simpleAdRenderingSetting = ... // Rendering settings for the native simple ad to be loaded
self.adLoader?.setNativeSimpleDelegate(self, nativeSimpleOptions: nativeSimpleOption)

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

On a successful ad request, the adLoader:didReceiveNativeSimpleAd: method of GFPAdLoaderDelegate is called.

GFPAdLoaderDelegate

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

On Load Success

When a native ad loads successfully, a GFPNativeSimpleAd object is returned as the response.
The GFPNativeSimpleAd object is used to create the native ad view (UIView). For details on how to construct the native ad view using the GFPNativeSimpleAd object, see the native ad view creation section.

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeSimpleAd: GFPNativeSimpleAd!) {
// Create ad view using the nativeSimpleAd object
...
}

On Load Failure

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

Rendering the Native Ad

Once GFPNativeSimpleAd has loaded successfully, you can render the native ad.
This requires a view object in which the native ad elements are defined, and this object must inherit from the GFPNativeSimpleAdView class. In this document, we use Interface Builder to configure the view.

Creating the Native Simple Ad View

  1. Create a view (xib) for the native ad, and in Xcode's Identity Inspector tab, set the Custom Class to GFPNativeSimpleAdView. Example image

  2. Create each asset view (title, body, etc.) that makes up the native ad view, and connect them to the corresponding outlets of GFPNativeSimpleAdView in the Connections Inspector tab.

GFPNativeSimpleAdView inherits from GFPNativeBaseView, and the mediaView outlet is defined in GFPNativeBaseView.h. Example image

  • The mediaView used to display the ad's video or image must also have its Custom Class set to GFPMediaView. Example image
  1. After loading the native ad, you can implement it as shown below.

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeSimpleAd: GFPNativeSimpleAd!) {

// Register native ad object and delegate
self.nativeSimpleAd = nativeSimpleAd
self.nativeSimpleAd?.delegate = self

// Setting the native ad on the view object starts mediaView rendering and view tracking.
self.nativeSimpleAdView?.nativeAd = nativeSimpleAd

// Add subview
self.view.addSubview(self.nativeSimpleAdView)
}

GFPNativeSimpleAdDelegate

Events are delivered when the native ad is shown or clicked.

On Ad Impression

func nativeSimpleAdWasSeen(_ nativeSimpleAd: GFPNativeSimpleAd) {
...
}

On Ad Rendered

func nativeSimpleAdWasRendered(_ nativeSimpleAd: GFPNativeSimpleAd) {
...
}

On Click

func nativeSimpleAdWasClicked(_ nativeSimpleAd: GFPNativeSimpleAd) {
...
}

On Rendering Error

func nativeSimpleAd(_ nativeSimpleAd: GFPNativeSimpleAd, didFailWithError error: GFPError) {
...
}

On Ad Media View Size Change

Since Native Simple is a single-image ad, upon receiving this event you must update the size of the Native Simple Ad View and the Media View.

func nativeSimpleAd(_ nativeSimpleAd: GFPNativeSimpleAd, didChangeMediaViewSizeWith size: CGSize) {
...
}

On Ad Muted by User

When an ad is muted, the service is notified via a callback. After muting, NAMSDK displays a message saying "This ad will no longer be shown." Whether to remove the ad from the screen or keep it visible is determined by the service's policy.

func nativeSimpleAdWasMuted(_ nativeSimpleAd: GFPNativeSimpleAd) {

}

On Mute Cancelled

func nativeSimpleAdWasCanceledMute(_ nativeSimpleAd: GFPNativeSimpleAd) {

}

In-App Browser Presented / Dismissed

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

func nativeSimpleAdDidPresentDefaultInAppBrowser(_ nativeSimpleAd: GFPNativeSimpleAd) {
// In-app browser presented
}

func nativeSimpleAdDidDismissDefaultInAppBrowser(_ nativeSimpleAd: GFPNativeSimpleAd) {
// In-app browser dismissed
}

Lazy Loading Media Load Success / Failure

Called when media loading completes or fails when Lazy Loading is in use.

func nativeSimpleAdDidLoadMedia(_ nativeSimpleAd: GFPNativeSimpleAd) {
// Media loading completed
}

func nativeSimpleAdDidFailToLoadMedia(_ nativeSimpleAd: GFPNativeSimpleAd) {
// Media loading failed
}

Others

Ad Invalidation Check

Native simple ads have an expiration time, so when displaying preloaded and cached ads, you must use the isAdInvalidate method to check if the ad has expired. If you display an expired ad, you will not receive compensation for ad impressions.


func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeSimpleAd: GFPNativeSimpleAd!) {

// Register native ad object and delegate
self.nativeSimpleAd = nativeSimpleAd
self.nativeSimpleAd?.delegate = self

// Check if ad is already expired or invalidated, and do not show ad if that is the case.
// You will not get paid to show an invalidated ad.
if nativeSimpleAd.isAdInvalidate {
print("This ad has been invalidated. Try again!")
return
}

// Setting the native ad on the view object starts mediaView rendering and view tracking.
self.nativeSimpleAdView?.nativeAd = nativeSimpleAd

// Add subview
self.view.addSubview(self.nativeSimpleAdView!)
}