HyBid Banner Ads (Pre v:2.0.0) - pubnative/pubnative-hybid-ios-sdk GitHub Wiki
Banner Ads will be rendered using the HyBid SDK.
Requirements
Ad Zone ID
from the PubNative Publisher Dashboard
Create a HyBidBannerAdView
- Import
HyBid
into your class.
Swift:
import HyBid
Objective-C:
#import <HyBid/HyBid.h>
- Create a
HyBidBannerAdView
property and initialize it. (For the sake of simplicity, we use Interface Builder. You can also create theHyBidBannerAdView
property programmatically.)
Swift:
@IBOutlet weak var bannerAdView: HyBidBannerAdView!
Objective-C:
@property (weak, nonatomic) IBOutlet HyBidBannerAdView *bannerAdView;
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
).
Swift:
self.bannerAdView.load(withZoneID: <YOUR AD ZONE ID HERE>, andWith: self)
Objective-C:
[self.bannerAdView loadWithZoneID:<YOUR AD ZONE ID HERE> andWithDelegate:self];
Swift:
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:")
}
}
Objective-C:
#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 HyBidBannerAdView
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 of 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.