Banner Ads
To load a banner, create a BIDBannerView and add it as a subview of your view hierarchy.
You can create banners of either 320x50 or 300x250 size:
#pragma mark - add banners to view
-(void)addBanner_320x50_to_view:(UIView*)view
{
BIDBannerView* banner = [BIDBannerView bannerWithFormat:[BIDAdFormat banner_320x50] delegate:(id)self];
banner.center = CGPointMake(CGRectGetMidX(view.bounds), CGRectGetMidY(view.bounds));
[view addSubview:banner];
}
-(void)addBanner_300x250_to_view:(UIView*)view
{
BIDBannerView* banner = [BIDBannerView bannerWithFormat:[BIDAdFormat banner_300x250] delegate:(id)self];
banner.center = CGPointMake(CGRectGetMidX(view.bounds), CGRectGetMidY(view.bounds));
[view addSubview:banner];
}//add banners to view
func addBanner_320x50_to_view(view:UIView) {
let banner = BIDBannerView.banner(with: BIDAdFormat.banner_320x50 as! BIDAdFormat, delegate: self)
banner.center = CGPoint(x:view.bounds.midX, y:view.bounds.midY)
view.addSubview(banner)
}
func addBanner_300x250_to_view(view:UIView) {
let banner = BIDBannerView.banner(with: BIDAdFormat.banner_300x250 as! BIDAdFormat, delegate: self)
banner.center = CGPoint(x:view.bounds.midX, y:view.bounds.midY)
view.addSubview(banner)
}Implement BIDBannerViewDelegate so that you are notified of when your ad is ready and of other ad-related events.
#pragma mark - BIDBannerViewDelegate protocol methods
- (void)bannerDidDisplay:(BIDBannerView *)banner adInfo:(BIDAdInfo *)adInfo
{
NSLog(@"Banner - did display ad. BannerView: %@, AdInfo: %@", banner, adInfo);
}
- (void)bannerDidFailToDisplay:(BIDBannerView *)banner adInfo:(BIDAdInfo *)adInfo error:(NSError *)error
{
NSLog(@"Banner - did fail to display ad. BannerView: %@, Error: %@", banner, error);
}
- (void)bannerDidClick:(BIDBannerView *)banner adInfo:(BIDAdInfo *)adInfo
{
NSLog(@"Banner - did click. BannerView: %@, AdInfo: %@", banner, adInfo);
}
- (void)allNetworksFailedToDisplayAdInBanner:(BIDBannerView *)banner
{
NSLog(@"Banner - allNetworksFailedToDisplayAdInBanner: %@", banner);
}
//This method is called by the auto-load algorithm only. It is not called during refresh or autorefresh.
- (void)bannerDidLoad:(BIDBannerView *)banner adInfo:(BIDAdInfo *)adInfo
{
NSLog(@"Banner - did load ad. BannerView: %@, AdInfo: %@", banner, adInfo);
}//BIDBannerViewDelegate protocol methods
func bannerDidDisplay(_ banner: BIDBannerView, adInfo: BIDAdInfo) {
print("Banner - did display ad. BannerView: \(banner) AdInfo: \(adInfo)")
}
func bannerDidFail(toDisplay banner: BIDBannerView, adInfo: BIDAdInfo, error: Error) {
print("Banner - did fail to display ad. BannerView: \(banner) AdInfo: \(adInfo) Error: \(error)")
}
func bannerDidClick(_ banner: BIDBannerView, adInfo: BIDAdInfo) {
print("Banner - did click. BannerView: \(banner) AdInfo: \(adInfo)")
}
func allNetworksFailedToDisplayAd(inBanner banner: BIDBannerView) {
print("Banner - allNetworksFailedToDisplayAd. BannerView: \(banner)")
}
//This method is called by the auto-load algorithm only. It is not called during refresh or autorefresh.
func bannerDidLoad(_ banner: BIDBannerView, adInfo: BIDAdInfo) {
print("Banner - did load ad. BannerView: \(banner) AdInfo: \(adInfo)")
}Stopping and Starting Auto-Refresh
There may be cases when you would like to stop auto-refresh, for instance, when you hide a banner ad or want to manually refresh.
Stop auto-refresh for a banner ad with the following code:
[bidBannerView stopAutorefresh];bidBannerView.stopAutorefresh()Start auto-refresh for a banner ad with the following code:
[bidBannerView startAutorefresh:30.0];bidBannerView.startAutorefresh(30.0)Manually refresh the contents with the following code. You must stop auto-refresh prior to calling refreshAd.
[bidBannerView refreshAd];bidBannerView.refreshAd()Stopping and Starting Auto-Load
By default, banners preload ads before any refresh attempt. So it is possible for a banner to use already preloaded ads instead of loading new ads during refresh attempts. To disable this feature you need to call the following method:
bidBannerView.autoload = NO;bidBannerView.autoload = falseLast updated
Was this helpful?