PubNative's Native Ads follow the natural form and function of the user experience. Native Ads take the shape into which they are placed. They provide content of the ad to the publisher, it's up to the publisher to make a design of the ad according to the app.

Getting Started

  • Before integrating Native Ads into your app, you’ll need to create an account on PubNative and integrate the PubNative iOS SDK into your project.
  • Add a Native Ad unit to your app in the PubNative dashboard.
  • Make sure you have added the ad network SDKs you wish to use to your app.

For Native Ads, first, you need to create a request then fill it with your data and start it providing a callback for the ad response.

Integration Steps

Request Native Ad

In order to request an ad, you need to create a request, fill it with your data and start it providing a callback for the ad response.

You can set up several data before starting the request by using the PNRequest helper methods. This is an optional usage but in the long term, it will seriously improve your ad placement behavior.

let request = PNRequest()
request.start(withAppToken:"<APP_TOKEN>", placementName:"<PLACEMENT_NAME>", delegate: self)
PNRequest *request = [[PNRequest alloc] init];
[request startWithAppToken:@"<APP_TOKEN>" placementName:@"<PLACEMENT_NAME>" delegate: self];

For getting callbacks from PNRequest, you should implement PNRequestDelegate for your class:

class YourClass: PNRequestDelegate
{
//...
func pubnativeRequestDidStart(_ request: PNRequest!) 
{
    // Request started
}
    
func pubnativeRequest(_ request: PNRequest!, didFail error: Error!) 
{
    // Request failed
}
    
func pubnativeRequest(_ request: PNRequest!, didLoad ad: PNAdModel!) 
{
    // Request return the Ad
}
//...
}
@interface YourClass () <PNRequestDelegate>
//...
-(void)pubnativeRequestDidStart:(PNRequest *)request
{
    // Request started
}

-(void)pubnativeRequest:(PNRequest *)request didLoad:(PNAdModel *)ad
{
    // Request return the Ad
}

-(void)pubnativeRequest:(PNRequest *)request didFail:(NSError *)error
{
    // Request failed
}
//...

Cache Resource
By default, resources would be cached before serving the ad. You can set it to false as follows in order to use URLs to download resources like an icon, banner etc.

request.cacheResources = Bool
request.cacheResources = BOOL;

Fill View With Data

To display Native Ads, you need to create a renderer instance, (type of PNAdModelRenderer) and bind all your view elements into it and then pass this instance to PNAdModel's renderAd() method:

let renderer = PNAdModelRenderer()
renderer.titleView = adTitle               // Ad's title view
renderer.descriptionView = adDescription   // Ad's description view
renderer.iconView = adIcon                 // Ad's icon view
renderer.bannerView = adBanner             // Ad's banner view
renderer.starRatingView = adRating         // Ad's rating view
renderer.callToActionView = adCallToAction // Ad's CTA view
renderer.contentInfoView = contentInfo     // Ad's content info view

adModel.(renderer)
PNAdModelRenderer *renderer = [[PNAdModelRenderer alloc] init];
renderer.titleView = adTitle;               // Ad's title view
renderer.descriptionView = adDescription;   // Ad's description view
renderer.iconView = adIcon;                 // Ad's icon view
renderer.bannerView = adBanner;             // Ad's banner view
renderer.starRatingView = adRating;         // Ad's rating view
renderer.callToActionView = adCallToAction; // Ad's CTA view
renderer.contentInfoView = contentInfo;     // Ad's content info view

[adModel renderAd:renderer];

The adModel will automatically fill bounded views with right data.

Track Native Ad

Once you have rendered your ad, you should make the model start tracking your view so we can confirm the impression and handle the clicks, this can be done with the following method from the PNAdModel

adModel.startTrackingView(<AD_CONTAINER_VIEW>, with: <YOUR_CONTROLLER>)
[adModel startTrackingView:<AD_CONTAINER_VIEW> withViewController:<YOUR_CONTROLLER>];

If your ad is removed from the screen or you're exiting the ViewController, you'll need to stop the tracking process with the following method:

adModel.stopTracking()
[adModel stopTracking];

You can also set up a PNAdModelDelegate to listen for callbacks on the tracking process.

class YourClass: PNAdModelDelegate 
{
//...
adModel.delegate = self
//...
func pubantiveAdDidConfirmImpression(ad: PNAdModel!)
{
    //Impression was just recorded
}

func pubnativeAdDidClick(ad: PNAdModel!)
{
    //The ad was clicked, the ad will be opened right after this
}
//...
}
@interface YourInterface () PNAdModelDelegate
//...
adModel.delegate = self;
//...
- (void)pubantiveAdDidConfirmImpression:(PNAdModel *)ad
{
    //Impression was just recorded
}

- (void)pubnativeAdDidClick:(PNAdModel *)ad
{
    //The ad was clicked, the ad will be opened right after this
}
//...