Getting Started
Native Simple ads contain single native view that conatins an image or rich native contents.
Prerequisites
Implementing View Controller
In the view controller that will present the ad view as subview,
-
add these properties
GFPAdLoader *adLoader
GFPNativeSimpleAd *bannerView
-
and implement these delegate protocols
GFPAdLoaderDelegate
GFPNativeSimpleAdDelegate
- Swift
- Objective-C
// MyViewController.h
import GFPSDK
class MyViewController : UIViewController, GFPAdLoaderDelegate, GFPNativeSimpleAdDelegate {
private var adLoader : GFPAdLoader?
private var nativeSimpleAd : GFPNativeSimpleAd?
private var nativeSimpleAdView : GFPNativeSimpleAdView?
}
// MyViewController.h
@import GFPSDK;
@interface MyViewController : UIViewController <GFPAdLoaderDelegate, GFPNativeSimpleAdDelegate>
@property (nonatomic) GFPAdLoader *adLoader;
@property (nonatomic) GFPNativeSimpleAd *nativeSimpleAd;
@property (nonatomic) GFPNativeSimpleAdView *nativeSimpleAdView;
@end
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. -
Set
GFPAdLoaderDelegate
onGFPAdLoader
.
Do not use GFPAdLoader
instance for multiple ad requests, since it's only designed for single ad request.
- Swift
- Objective-C
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.renderingSetting = ...
self.adLoader?.setNativeSimpleDelegate(self, nativeSimpleOptions: nativeSimpleOption)
self.adLoader?.delegate = self
self.adLoader?.loadAd()
}
- (void)viewDidLoad {
[super viewDidLoad];
GFPAdParam *adParam = [[GFPAdParam alloc]init];
adParam.yearOfBirth = 1990;
adParam.gender = GFPAdParamGenderTypeMale;
...
self.adLoader = [[GFPAdLoader alloc] initWithUnitID:self.unitID
rootViewController:self
adParam:adParam];
GFPAdNativeSimpleOptions *nativeSimpleOptions = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOptions.simpleAdRenderingSetting = ...;
[self.adLoader setNativeSimpleDelegate:self nativeSimpleOptions:nativeSimpleOptions];
self.adLoader.delegate = self;
[self.adLoader loadAd];
}
Premium Video Ad Delegate
GFPNativeVideoEventDelegate
handles AVPlayer in Native Simple ads that conatins videos (NS Rich Video Ads).
GFPNativeSimpleAdRenderingSetting *renderingSetting = [[GFPNativeSimpleAdRenderingSetting alloc] init];
nativeSimpleOptions.renderingSetting.videoEventDelegate = ...;
GFPNativeVideoEventDelegate
-
On Video Will Play. It is called before
AVPlayer
play:
- (void)nativeAd:(NSObject *)nativeAd richVideoWillPlayWith:(BOOL)isMuted;
-
On Video Did Play. It is called after
AVPlayer
play:
- (void)nativeAd:(NSObject *)nativeAd richVideoDidPlayWith:(BOOL)isMuted;
-
On Video Will Pause. It is called before
AVPlayer
pause:
It does not include situations where video being stopped due to deallocation or errors.
- (void)nativeAd:(NSObject *)nativeAd richVideoWillStopWith:(BOOL)isMuted;
-
On Video Will Pause. It is called after
AVPlayer
pause:
andstatus
being updated.It includes situation where video being stopped due to deallocation.
- (void)nativeAd:(NSObject *)nativeAd richVideoDidStopWith:(BOOL)isMuted;
-
On IsMute Changed.
- (void)nativeAd:(NSObject *)nativeAd richVideoMuteChanged:(BOOL)isMuted;
Implementing Interface Builder
GFPNativeAd\ requires to be subclassed by an interface builder view.
Create an .xib file with a view and subclass GFPNativeSimpleAdView
and its subviews.
-
In your .xib file, open Identity Inspector tab on Xcode, than set Custom Class to
GFPNativeSimpleAdView
. -
Add subviews that corresponds to title label, body label, etc. onto the
GFPNativeSimpleAdView
and connect them to outlets on the Connections Inspector tab. -
Add a view and set outlet for
GFPNativeBaseView.mediaView
Do not allocate more than one GFPNativeSimpleAdView
for one GFPNativeAd
.
GFPAdLoaderDelegate
On Ad Load Success
- Swift
- Objective-C
func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeSimpleAd: GFPNativeSimpleAd!) {
// Get estimated ad height
let estimateHeight = nativeSimpleAd.estimateHeight(with: self.nativeSimpleAdView?.bounds.size.width)
// Set `GFPNativeSimpleAdDelegate`
self.nativeSimpleAd = nativeSimpleAd
self.nativeSimpleAd?.delegate = self
// As soon as assigning a `GFPNativeSimpleAd` to the `GFPNativeSimpleAdView`, it starts tracking impressions, and rendering iconView and mediaView images.
self.nativeSimpleAdView?.nativeAd = nativeAd
// Add as subview
self.view.addSubview(self.nativeSimpleAdView!)
}
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd {
// Get estimated ad height
CGFloat estimateHeight = [nativeSimpleAd estimateHeightWith: self.nativeSimpleAdView.bounds.size.width];
// Set `GFPNativeSimpleAdDelegate`
self.nativeSimpleAd = nativeSimpleAd;
self.nativeSimpleAd.delegate = self;
// As soon as assigning a `GFPNativeSimpleAd` to the `GFPNativeSimpleAdView`, it starts tracking impressions, and rendering iconView and mediaView images.
self.nativeSimpleAdView.nativeAd = nativeSimpleAd;
// Add as subview
[self.view addSubView:self.nativeSimpleAdView];
}
On Ad Load Failure
- Swift
- Objective-C
func adLoader(_ unifiedAdLoader: GFPAdLoader!, didFailWithError error: GFPError!, responseInfo: GFPLoadResponseInfo!) {
...
}
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didFailWithError:(GFPError *)error responseInfo:(GFPLoadResponseInfo *)responseInfo {
...
}
Use GFPNativeSimpleAd
estimateHeightWith:
to set height of the ad view.
Ad Size changed afterward load are sent through GFPNativeSimpleAdDelegate
nativeSimpleAd:didChangeMediaViewSizeWith:
.
GFPNativeSimpleAdDelegate
On View Impression
- Swift
- Objective-C
func nativeSimpleAdWasSeen(_ nativeSimpleAd: GFPNativeSimpleAd) {
...
}
- (void)nativeSimpleAdWasSeen:(GFPNativeSimpleAd *)nativeSimpleAd {
...
}
On Rendered Impression
- Swift
- Objective-C
func nativeSimpleAdWasRendered(_ nativeSimpleAd: GFPNativeSimpleAd) {
...
}
- (void)nativeSimpleAdWasRendered:(GFPNativeSimpleAd *)nativeSimpleAd {
...
}
On Click
- Swift
- Objective-C
func nativeSimpleAdWasClicked(_ nativeSimpleAd: GFPNativeSimpleAd) {
...
}
- (void)nativeSimpleAdWasClicked:(GFPNativeSimpleAd *)nativeSimpleAd {
...
}
On Rendering Error
- Swift
- Objective-C
func nativeSimpleAd(_ nativeSimpleAd: GFPNativeSimpleAd, didFailWithError error: GFPError) {
...
}
- (void)nativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd didFailWithError:(GFPError *)error {
...
}
On Media View Size Change
didChangeMediaViewSizeWith:
delivers GFPNativeSimpleAdView.mediaView
's size change, wich is the size of its content.
Be minded that it does not mean that GFPNativeSimpleAdView
resizes automatically. On didChangeMediaViewSizeWith:
called, adjust the frame of GFPNativeSimpleAdView
tailored for your app.
- Swift
- Objective-C
func nativeSimpleAd(_ nativeSimpleAd: GFPNativeSimpleAd, didChangeMediaViewSizeWith size: CGSize) {
...
}
- (void)nativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd didChangeMediaViewSizeWith:(CGSize)size {
...
}
On Premium Rich Media View Size Change
It notifies media view's size change, but only applies to Premium Rich Ads.
- Swift
- Objective-C
func nativeSimpleAd(_ nativeSimpleAd: GFPNativeSimpleAd, didChangeRichAdSizeWith:(CGSize)size {
...
}
- (void)nativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd didChangeRichAdSizeWith:(CGSize)size {
...
}
On Ad Muted
“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.
- Swift
- Objective-C
func nativeSimpleAdWasMuted(_ nativeSimpleAd: GFPNativeSimpleAd) {
}
- (void)nativeSimpleAdWasMuted:(GFPNativeSimpleAd *)nativeSimpleAd {
}