Banners iOS
Creating A Banner
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 |
MERC | 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 equal to its CHBBannerSize
property.
Example:
- (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]]];
}
Note
- 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
To make the banner show an ad, first create and present it, then call this method:
[banner showFromViewController:self];
Banner Delegates Methods
Every banner has an optional delegate which can be provided when initialized or assigned afterwards. Get notified and respond to events related to the banner life-cycle by implementing delegate methods:
didCacheAd
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.
Example:
- (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]]];
}
willShowAd
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:
- (void)willShowAd:(CHBShowEvent *)event {
// Make any necessary UI updates
}
didShowAd
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:
(void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error {
if (error) {
// Handle error
} else {
[event.ad cache];
}
shouldConfirmClick
shouldConfirmClick
- (BOOL)shouldConfirmClick:(CHBClickEvent *)event confirmationHandler:(void(^)(BOOL))confirmationHandler;
- Description: Called whenever the user clicks an ad to give a chance to the developer to present a confirmation gate before the click is handled.
- Parameter Event: A click event with info related to the ad clicked.
- Parameter
confirmationHandler
: A block to be executed only if the return value isYES
. It takes aBOOL
parameter that indicates if the confirmation gate was passed or not. - Returns:
YES
, if the handling of the triggering click should be paused for confirmation.NO
, if the click should be handled without confirmation.Warning
If you return
YES
in your implementation make sure to execute theconfirmationHandler
at some point, since the ad flow will be paused until then. If you use the event’s view controller to present a confirmation view make sure it has been dismissed by the time you execute theconfirmationHandler
.
- Discussion: If you return
YES
it is your responsibility to implement some confirmation method that triggers the execution of theconfirmationHandler
. If this method is not implemented clicks will be handled without confirmation.
Example:
(BOOL)shouldConfirmClick:(CHBClickEvent *)event confirmationHandler:(void(^)(BOOL))confirmationHandler
if (self.needsClickConfirmation) {
MyAwesomeAgeGate *ageGate = [[MyAwesomeAgeGate alloc] initWithCompletion:^(BOOL confirmed) {
[ageGate dismissViewControllerAnimated:YES completion:^{
confirmationHandler(confirmed);
}];
}];
[event.viewController presentViewController:ageGate animated:YES completion:nil];
return YES;
} else {
return NO;
}
}
didClickAd
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 into the opening of a link an error will be provided explaining why.
Example:
(void)didClickAd:(CHBClickEvent *)event error:(nullable CHBClickError *)error {
if (error) {
// Handle error
} else {
// Maybe pause ongoing processes like video or gameplay.
}
}
didFinishHandlingClick
didFinishHandlingClick
- (void)didFinishHandlingClick:(CHBClickEvent *)event error:(nullable CHBClickError *)error;
- Description: Called when the link viewer presented as 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 App Store app sheet has been dismissed, or that the user came back to the app after the link was opened on an external application.
Example:
(void)didFinishHandlingClick:(CHBClickEvent *)event error:(nullable CHBClickError *)error {
// Resume processes previously paused on didClickAd:error: implementation.
}
Updated 4 days ago