Banner Ads
To load a banner, create a BannerView
and add it as a subview of your view hierarchy.
You can create banners of either 320x50, 300x250 or 728x90 size:
fun createBanner_320x50(activity : Any?) {
banner = BIDBanner(activity, BIDAdFormat.banner_320x50)
banner.setBannerViewDelegate(bannerShowDelegate)
}
fun createBanner_300x250(activity : Any?) {
banner = BIDBanner(activity, BIDAdFormat.banner_300x250)
banner.setBannerViewDelegate(bannerShowDelegate)
}
fun createBanner_728x90(activity : Any?) {
banner = BIDBanner(activity, BIDAdFormat.banner_728x90)
banner.setBannerViewDelegate(bannerShowDelegate)
}
Implement BIDBannerShow
so that you are notified of when your ad is ready and of other ad-related events.
//BIDBannerShow protocol methods
var bannerShow: BIDBannerShow? = object : BIDBannerShow {
override fun load(info: BIDAdInfo, adView: BIDBanner) {
print("Banner - adViewDidLoadAd. AdView: $adView, AdInfo: $info")
}
override fun display(info: BIDAdInfo, adView: BIDBanner) {
print("Banner - didDisplayAd. AdView: $adView, AdInfo: $info")
}
override fun failToDisplay(info: BIDAdInfo, adView: BIDBanner, error: String) {
print("Banner - didFailToDisplayAd. AdView: $adView, Error:$errors")
}
override fun click(info: BIDAdInfo, adView: BIDBanner) {
print("Banner - didClicked. AdView: $adView, AdInfo: $info")
}
override fun allNetworksFailedToDisplay(error: String) {
print("Banner - allNetworksFailedToDisplayAd - error: $error")
}
}
To display a banner you will need to bind it to FrameLayout or ConstraintLayout for Android and UIView for iOS
banner.bindBanner(container)
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 refresh it manually.
Stop auto-refresh for a banner ad with the following code:
banner.stopAutorefresh()
Start auto-refresh for a banner ad with the following code:
banner.startAutorefresh(30.0)
Manually refresh the contents with the following code. You must stop auto-refresh prior to calling refreshAd
.
banner.refresh()
Destroying Banners
Once you're finished with a banner ad, it's essential to clean up its resources by invoking the destroy() method. Neglecting this step could lead to a deterioration in your app's performance
banner.destroy()
Last updated
Was this helpful?