Displaying banner ads involves creating banner instances and listening for ad-related events.
The PSDK provides a list of companion banner ads associated with a linear ad through the PTMediaPlayerAdPlayStartedNotification notification.
For each companion ad, the PSDK indicates which type or types are available for your application to use.
Each banner instance (a PTAdAsset) contains information necessary for displaying the companion banner, such as width, height, resource type (html, iframe, or static), and data.
This is usually a div, and your function uses the div ID to display the banner.
For example:
- (void) onMediaPlayerAdPlayStarted:(NSNotification *) notification {
_currentAd = [notification.userInfo objectForKey:PTMediaPlayerAdKey];
if (_currentAd != nil) {
[self removeAllBanners]; // remove any existing PTAdBannerView views
// banners
if (_currentAd.companionAssets && _currentAd.companionAssets.count > 0) {
PTAdAsset *bannerAsset = [_currentAd.companionAssets objectAtIndex:0];
PTAdBannerView *bannerView = [[PTAdBannerView alloc] initWithAsset:bannerAsset];
bannerView.player = self.player;
bannerView.delegate = self;
bannerView.frame = CGRectMake(0.0, 0.0, bannerAsset.width, bannerAsset.height);
[_adBannerView.bannerView addSubview:bannerView];
}
}
}