Banners
Creating A Banner Ad π
To create a banner, use the initializer initWithSize:location:delegate:
and provide a size, Chartboost location, and an optional delegate. A banner ad has a CHBBannerSize
which corresponds to the viewβs intrinsicContentSize
.
There are currently 3 banner sizes:
Name | Field | Size |
---|---|---|
Standard | CHBBannerSizeStandard |
320 x 50 |
Medium | CHBBannerSizeMedium |
300 x 250 |
Leaderboard | CHBBannerSizeLeaderboard |
728 x 90 |
Automatic Sizing: If AutoLayout
is being used, give the banner an X and Y position constraint and it will be automatically sized.
Manual Sizing: Assign frame sizes manually and make sure the banner frame size is equal to its CHBBannerSize
property.
Example:
-
func createBanner() { banner = CHBBanner(size: CHBBannerSizeStandard, location:CBLocationMainMenu, delegate: self) banner.translatesAutoresizingMaskIntoConstraints = false self.view.addSubview(banner) NSLayoutConstraint.activate([ banner.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor), banner.centerXAnchor.constraint(equalTO: self.view.centerXAnchor) ]) }
-
- (void)createBanner { CHBBanner *banner = [[CHBBanner alloc] initWithSize:CHBBannerSizeStandard location:CBLocationMainMenu delegate:self]; banner.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:banner]; [NSLayoutConstraint activateConstraints:@[[banner.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor], [banner.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor]]]; }
- We do not serve banner ads to apps that are opted-out of behavioral targeting.
- You do not need to create a Banner Publishing Campaign on the Chartboost Dashboard. The banner ads are delivered through our Exchange. You only need to call on them via the SDK.
- Your banner analytics are available in the App Analytics section of your Chartboost Dashboard.
- Multiple banners can be displayed at once if desired.
Showing Banner Ads π
After creating your banner ad, show it by calling this method:
-
banner.show(from:self)
-
[banner showFromViewController:self];
Banner Delegates Methods π
Every banner has an optional delegate which can be provided when initialized or assigned afterward. Get notified and respond to events related to the banner life-cycle by implementing delegate methods:
didCacheAd
π
(void)didCacheAd:(CHBCacheEvent _)event error:(nullable CHBCacheError _)error
- Description: Called after a cache call if
- an ad has been loaded from the Chartboost servers and cached.
- an ad has failed to be loaded from the Chartboost servers.
- Parameter Event: A cache event with info related to the cached ad.
- Parameter Error: An error specifying the failure reason, or
nil
if the operation was successful. - ** Discussion:** Get notified of when an ad is ready to be shown after the cache method has been called.
willShowAd
π
- (void)willShowAd:(CHBShowEvent \*)event;
- Description: Called after a
showFromViewController:
call, right before an ad is presented. - Parameter Event: A show event with info related to the ad to be shown.
- Parameter Error: An error specifying the failure reason, or
nil
if the operation was successful. - Discussion: Get notified of when an ad is about to be presented.
Example:
-
func willShowAd(_ event: CHBShowEvent) { // Make any necessary UI updates }
-
- (void)willShowAd:(CHBShowEvent *)event { // Make any necessary UI updates }
didShowAd
π
(void)didShowAd:(CHBShowEvent _)event error:(nullable CHBShowError _)error;
- Description: Called after a
showFromViewController:
call, either if the ad has been presented and an ad impression logged, or if the operation failed. - Parameter Event: A show event with info related to the ad shown.
- Parameter Error: An error specifying the failure reason, or
nil
if the operation was successful. - Discussion: Get notified of when the ad presentation process has finished.
Example:
-
func didShowAd(_ event: CHBShowEvent, error: CHBShowError?) { if error { // Handle error } else { event.ad.cache(); } }
-
- (void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error { if (error) { // Handle error } else { [event.ad cache]; }
didClickAd
π
- (void)didClickAd:(CHBClickEvent _)event error:(nullable CHBClickError _)error;
- Description: Called after an ad has been clicked.
- Parameter Event: A click event with info related to the ad clicked.
- Parameter Error: An error specifying the failure reason, or
nil
if the operation was successful. - Discussion: Get notified when an ad has been clicked. If the click does not result in the opening of a link an error will be provided explaining why.
Example:
-
func didClickAd(_ event: CHBClickEvent, error: CHBClickError?){ if error { // Handle error } else { // Maybe pause ongoing processes like video or gameplay when a banner ad is clicked } }
-
- (void)didClickAd:(CHBClickEvent *)event error:(nullable CHBClickError *)error { if (error) { // Handle error } else { // Maybe pause ongoing processes like video or gameplay when a banner ad is clicked } }
didFinishHandlingClick
π
- (void)didFinishHandlingClick:(CHBClickEvent _)event error:(nullable CHBClickError _)error;
- Description: Called when the link viewer presented as a result of an ad click has been dismissed.
- Parameter Event: A click event with info related to the ad clicked.
- Parameter Error: An error specifying the failure reason, or
nil
if the operation was successful. - Discussion: Get notified of when an ad click has been handled. This can mean an in-app web browser or StoreKit rendered ad has been dismissed, or that the user came back to the app after the link was opened on an external application.
Example:
-
func didFinishHandlingClick(_ event: CHBClickEvent, error: CHBClickError?){ // Resume processes previously paused on didClickAd:error: implementation. }
-
(void)didFinishHandlingClick:(CHBClickEvent *)event error:(nullable CHBClickError *)error { // Resume processes previously paused on didClickAd:error: implementation. }