Wiki
Clone wikiAATKit iOS / Proposal / BannerSticky2
Sticky Banner
Sticky Banner
- Sticky Banner
- Sticky Banner
- Create Sticky Banner
- Displaying Sticky Banner
- Optionally assign a specific view controller to a placement
- Assign a position to the Banner View
- Request Ad
- Convenience Getter for your placement
- AppNexus add native banners support
- Listening to statistics events
- Updating statistics delegate instance
- Sample App
- Sample App
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)
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;
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)
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 var bannerPlacement: AATKitPlacement { let placementName = "banner_name" guard let placement = AATKit.getPlacementWithName(placementName) else { return AATKit.createPlacement(withName: placementName, andType: .banner320x53) } return placement }
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;
Sample App
Sample App
Updated