Wiki

Clone wiki

AATKit iOS / Proposal / BannerSticky2

Sticky Banner

  1. Getting Started
  2. AATKit Initialisation
  3. Consent Handling
  4. Formats
  5. Targeting
  6. Advanced

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 banner_placement = [AATKit createPlacementWithName:@"banner_name" andType:AATKitBanner320x53];                                           

Swift:

let bannerPlacement = AATKit.createPlacement(withName: "banner_name", andType: .banner320x53)
n 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:

Objective-C:

UIView *banner_view = [AATKit getPlacementView:bannerPlacement];

Swift:

let bannerView = AATKit.getPlacementView(bannerPlacement)

Optionally 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.

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)

Assign a position to the Banner View

In order to add the banner view to your UIView you can use constraints or assign a position to it by calling: Objective-C:

//set banner position to the viewcontroller's bottom
CGPoint bannerPos = CGPointMake(0.0, 0.0);
[AATKit setPlacementPos:bannerPos forPlacement:bannerPlacement];

Swift:

//set banner position to the viewcontroller's bottom
let bannerPosition = CGPoint(x: 0.0, y: 0.0)
AATKit.setPlacementPos(bannerPosition, for: bannerPlacement)

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.
[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)
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

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

triggers the AATKit to send a one time Ad request.

Convenience Getter for your placement

In order to easily reuse a placement, you can use the following convenience getter snippet:

Objective-C:

#!objective-c
(NSObject<AATKitPlacement>*)bannerPlacement{
    static NSString* const placementName = @"myBannerPlacement";

    // for "?:" see: https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditionals
    return [AATKit getPlacementWithName:placementName] ?:
        [AATKit createPlacementWithName:placementName andType: AATKitBanner320x53];
Swift:
#!swift
var bannerPlacement: AATKitPlacement {
  let placementName = "banner_name"
  guard let placement = AATKit.getPlacementWithName(placementName) else {
      return AATKit.createPlacement(withName: placementName,
                                    andType: .banner320x53)
  }
  return placement
}
This snippet will instantiate your placement if it hasn't be created yet, or return its reference if it does.

AppNexus add native banners support

You can add AppNexus native banners support by adding the key AATKitAppNexusNativeBanner to your Info.plist and set the value to true

Listening to statistics events

AATKitStatisticsDelegate 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

+ (nullable NSObject<AATKitPlacement>*) createPlacementWithName:(nonnull NSString *) placementName
                                                        andType:(AATKitAdType)type
                                          andStatisticsDelegate:(nullable NSObject <AATKitStatisticsDelegate>*)statisticsDelegate

Updating statistics delegate instance

You can pass a new statistics delegate instance to the placement by using the following method in AATKitPlacement:

- (void)updateStatisticsDelegate:(nonnull NSObject <AATKitStatisticsDelegate> *)statisticsDelegate;
for more info about it please refer to AATKitStatisticsDelegate Guide

Sample App

Sample App

back (Home)

Updated