Wiki

Clone wiki

Banner Sample / AATKit 3 sticky banner migration

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

Instead of:

Objective-C:

id bannerPlacement = [AATKit createPlacementWithName:@"banner_name" andType:AATKitBanner320x53];                                           

Swift:

let bannerPlacement = AATKit.createPlacement(withName: "banner_name", andType: .banner320x53)
Use:

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

Displaying Sticky Banner

Fetch the UIView reference of the previously created banner placement and add it to your view controller view hierarchy by calling:

Instead of:

Objective-C:

UIView *banner_view = [AATKit getPlacementView:self.bannerPlacement];

Swift:

let bannerView = AATKit.getPlacementView(bannerPlacement)

Use:

Objective-C:

UIView *banner_view = [self.stickyBannerPlacement getPlacementView];

Swift:

let bannerView = bannerPlacement.getPlacementView()

Assign a specific view controller to a placement

Setting a view controller during initialization of the AATKit, or by using the method + (void) setViewController:(nullable UIViewController*)con; sets a global view controller used by all placements.

Passing the ViewController to the old SDK:

It's also possible to assign a placement specific view controller, by using the following method:

#!objective-c
+ (void) setPlacementViewController:(nullable UIViewController*)con forPlacement:(nonnull id) placement;
Setting a placement specific view controller will override any global view controller. This means, in order to not override a global view controller, the placement specific view controller has to set to nil.

Objective-C:

[AATKit setPlacementViewController:self forPlacement:bannerPlacement];

Swift:

AATKit.setPlacementViewController(self, for: bannerPlacement)

Passing the ViewController to the AATKit v3.x.x:

  • To pass the proper ViewController to AATKit, you should follow the following in the viewDidAppear method:

Objective-C:

[AATSDK controllerViewDidAppearWithController:self];
Swift:
#!swift
AATSDK.controllerViewDidAppear(controller: self)
* In the ViewController's viewWillDisappear method, you should do the following:

Objective-C:

[AATSDK controllerViewWillDisappear];
Swift:
#!swift
AATSDK.controllerViewWillDisappear()

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.

Instead of:

Objective-C:

//reload the banner placement each 30 seconds.
[AATKit startPlacementAutoReload:bannerPlacement];
// or for manual refresh time
[AATKit startPlacementAutoReloadWithSeconds:60 forPlacement:bannerPlacement];

Swift:

//reload the banner placement each 30 seconds.
AATKit.startPlacementAutoReload(bannerPlacement)
// or for manual refresh time
AATKit.startPlacementAutoReload(withSeconds: 60, for: bannerPlacement)

Use:

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

Instead of:

#!objective-c
+ (void) reloadPlacement:(id) placement; // must not call this if autoreload is enabled for this placement

Use:

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