Wiki
Clone wikiBanner Sample / Sticky Banner
Sticky Banner
Create Sticky Banner
A banner placement serves as a container for banner Ads. it is commonly used as a static, constantly shown, part of the app's presentation. The ad content of the banner changes over time. to create a placement you need to specify its name and size
Objective-C:
id<AATStickyBannerPlacement>* bannerPlacement = [AATSDK createStickyBannerPlacementWithName:@"banner_name" size:AATBannerPlacementSizeBanner300x50];
Swift:
let bannerPlacement: AATStickyBannerPlacement? = AATSDK.createStickyBannerPlacement(name: "banner_name", size: .banner320x53)
in order to work with the AddApptr backend, placement names must be constant at runtime, i.e. they shouldn't change on each app start. Note that any placement instance is supposed to be reused. Do not create a placement instance for each banner ad you want to display. . KEEP THE AMOUNT OF PLACEMENTS LOW. Each location where banner ads should be displayed corresponds to a placement instance. This instance will make sure that multiple banner ads of multiple ad networks will be displayed.
You have to specify a placement name, which allows for referencing the placement later on. Also, the type argument specifies the size of the ad to be displayed
Setting the view controller
You can set the current view controller for AATKit, you should set the viewController in your viewController viewDidAppear
method.
Objective-C:
[AATSDK controllerViewDidAppearWithController:<<your Current ViewController>>];
AATSDK.controllerViewDidAppear(controller: <<your Current ViewController>>)
In the ViewController's viewWillDisappear
method, you should do the following:
Objective-C:
[AATSDK controllerViewWillDisappear];
Swift:
AATSDK.controllerViewWillDisappear()
Displaying Sticky Banner
Fetch the UIView reference of the previously created banner placement and add it to your view controller view hierarchy by calling:
Objective-C:
UIView *banner_view = [self.stickyBannerPlacement getPlacementView];
Swift:
let bannerView = bannerPlacement.getPlacementView()
Request Ad
Request an Ad banner Ad can be requested in multiple ways. First, you can enable auto reload, which by default does reload the banner placement each 30 seconds.
Objective-C:
//reload the banner placement each 30 seconds. [self.stickyBannerPlacement startAutoReload]; // or for manual refresh time [self.stickyBannerPlacement setAutoreloadIntervalWithSeconds:30];
Swift:
//reload the banner placement each 30 seconds. bannerPlacement.startAutoReload() // or for manual refresh time bannerPlacement.setAutoreloadInterval(seconds: 30)
minimum recommended refresh time is 30 secconds to avoid too many requests. the previous method load and display a new ad automatically each TimeInterval,
Lastly, requesting an Ad can also be done manually.
Calling the method
placement.reload()
triggers the AATKit to send a one time Ad request.
Listening to events
To register for banner ad events, set the delegate property on AATStickyBannerPlacement
to an object that implements the AATStickyBannerPlacementDelegate
protocol.
Objective-C:
[self.bannerPlacement setDelegate:self];
Swift:
bannerPlacement.delegate = self
Implementing AATStickyBannerPlacementDelegate
func aatHaveAd() { /// This method will be called when there is an ad } func aatNoAd() { /// This method will be called when there is no ad available } func aatAdCurrentlyDisplayed() { /// This method will be called with the ad display event } func aatResumeAfterAd() { /// This method will be called when the app resumes after displaying an ad }
Listening to statistics events
AATStatisticsDelegate is an optional delegate you can implement if you need to get notified about statistics events. and pass it to placement while creating it using this method
bannerPlacement.statisticsDelegate = self
for more info about it please refer to AATStatisticsDelegate Guide
Sample App
Updated