Banner Ads will be rendered using the HyBid SDK.

Requirements

  • Ad Zone ID from the PubNative Publisher Dashboard.

Demo App

You can find a demo app with code samples for this type of integration here.

Create a HyBidAdView

  1. Import HyBid into your class.
import HyBid
#import <HyBid/HyBid.h>
  1. Create a HyBidAdView property and initialize it. (For the sake of simplicity, we use Interface Builder. You can also create the HyBidAdView property programmatically.)

IMPORTANT NOTES

  • If you create this property via Interface Builder, make sure to set the adSize property before you request the ad.
  • If you create this property via programmatically, you can set the adSize property at the initialization step.
  • HyBidAdSize supports different sizes such as(SIZE320x50, SIZE_300x250, SIZE_728x90, etc.) For the full list check the HyBidAdSize.h file. (For the sake of simplicity, we use SIZE320x50.)_
// Interface Builder

@IBOutlet weak var bannerAdView: HyBidAdView!
//....
//...
self.bannerAdView.adSize = HyBidAdSize.size_320x50
//...
//....

// Programmatically

var bannerAdView : HyBidAdView!
//....
//...
self.bannerAdView = HyBidAdView(size: HyBidAdSize.size_320x50)
//...
//....
// Interface Builder

@property (weak, nonatomic) IBOutlet HyBidAdView *bannerAdView;
//....
//...
self.bannerAdView.adSize = HyBidAdSize.SIZE_320x50
//...
//....

// Programmatically

@property (nonatomic, strong) HyBidAdView *bannerAdView;
//....
//...
self.bannerAdView = [[HyBidAdView alloc] initWithSize:HyBidAdSize.SIZE_320x50];
//...
//....

Requesting and displaying the ad

Use the load method to request an Ad by, passing your Ad Zone ID and also your registered view controller as the bannerAdView's delegate (HyBidAdViewDelegate).

self.bannerAdView.load(withZoneID: <YOUR AD ZONE ID HERE>, andWith: self)
[self.bannerAdView loadWithZoneID:<YOUR AD ZONE ID HERE> andWithDelegate:self];
extension ViewController : HyBidAdViewDelegate
{
    func adViewDidLoad(_ adView: HyBidAdView!)
    {
        print("Banner Ad View did load:")
    }
    
    func adView(_ adView: HyBidAdView!, didFailWithError error: Error!)
    {
        print("Banner Ad View did fail with error: \(error.localizedDescription)")
    }
    
    func adViewDidTrackClick(_ adView: HyBidAdView!)
    {
        print("Banner Ad View did track click:")
    }
    
    func adViewDidTrackImpression(_ adView: HyBidAdView!) 
    {
        print("Banner Ad View did track impression:")
    }
}
#pragma mark - HyBidAdViewDelegate

- (void)adViewDidLoad:(HyBidAdView *)adView
{
    NSLog(@"Banner Ad View did load:");
}

- (void)adView:(HyBidAdView *)adView didFailWithError:(NSError *)error
{
    NSLog(@"Banner Ad View did fail with error: %@",error.localizedDescription);
}

- (void)adViewDidTrackClick:(HyBidAdView *)adView
{
    NSLog(@"Banner Ad View did track click:");
}

- (void)adViewDidTrackImpression:(HyBidAdView *)adView
{
    NSLog(@"Banner Ad View did track impression:");
}

Once the ad is loaded successfully from the server, the HyBidAdView will render it and notify when it's ready via the adViewDidLoad callback. Any error during fetch or rendering will be received via the adViewDidFailWithError callback.

adViewDidTrackImpression and adViewDidTrackClick just notify for clicks and impressions. No code needs to be added there. Use those callbacks in case you want to hide the ad after click or some similar use case.

Disable asset caching

In some integration scenarios like in-app bidding, pre-caching the ad assets is not needed since there’s no guarantee that the ad will end up being displayed. For this reason the HyBid SDK provides controls to disable ad caching. This will allow you to access properties like the bid price right after the ad server has responded with a creative.

To disable the ad caching, the function:

func isAutoCacheOnLoad(_ isAutoCacheOnLoad: Bool)
- (void)setIsAutoCacheOnLoad:(BOOL)isAutoCacheOnLoad;

in the HyBidAdView can be used. It is enabled by default.

var bannerAdView = HyBidAdView(size: .size_320x50)
bannerAdView?.isAutoCacheOnLoad = false
HyBidAdView *bannerAdView = [[HyBidAdView alloc] initWithSize:HyBidAdSize.SIZE_320x50];
[bannerAdView setIsAutoCacheOnLoad:NO];

Once the ad has finished loading, the prepare function can be used to force a creative cache. This will ensure that the interstitial renders faster, thus creating a smoother user experience.

func adViewDidLoad(_ adView: HyBidAdView!) {
    bannerAdView.prepare()
}
- (void)adViewDidLoad:(HyBidAdView *)adView {
    [self.bannerAdView prepare];
}

You can use the show function as usual to render the ad. Even if prepare is not called, the rendering will work as well but the user might notice a small delay for video ads.

Return to the HyBid