iOS

The Chartboost SDK’s delegate methods allow you to exercise a greater degree of control over your integration. For example, you can:
  • Log debug messages when your game attempts to load an interstitial.
  • Prevent ads from showing the first time a user plays your game.
  • Determine whether a user has clicked an ad or just closed it – and react accordingly.
  • Prevent an interstitial page appearing when and where it would interfere with your game.
You can view the Chartboost iOS SDK methods at your disposal in the Chartboost.h header file in the Chartboost framework. You can see many of these methods in use within the sample project included with your iOS SDK download.  
▲ Back to top

Click here to view iOS SDK configuration methods.  
▲ Back to top

Before using any delegate functions, set the Chartboost delegate with delegate:self in your Chartboost initialization code:
#import <Chartboost/Chartboost.h>
#import <Chartboost/CBNewsfeed.h>
#import "AppDelegate.h"

@interface AppDelegate ()
@end

@implementation AppDelegate

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Initialize the Chartboost library
    [Chartboost startWithAppId:@"YOUR_CHARTBOOST_APP_ID”
                  appSignature:@ "YOUR_CHARTBOOST_APP_SIGNATURE”
                    completion:^(BOOL success) {
        // Chartboost was initialized if success is YES
    }];
    return YES;
}
 
▲ Back to top

Description: Called after a cache call, either if an ad has been loaded from the Chartboost servers and cached, or tried to but failed.
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: Implement to be notified of when an ad is ready to be shown after the cache method has been called.
- (void)didCacheAd:(CHBCacheEvent *)event error:(nullable CHBCacheError *)error;

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.
Discussion: Implement to be notified of when an ad is about to be presented.
- (void)willShowAd:(CHBShowEvent *)event;

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: Implement to be notified of when the ad presentation process has finished.
- (void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error;

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 is YES. It takes a BOOL 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 the confirmationHandler 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 the confirmationHandler.
Discussion: If you return YES it is your responsibility to implement some confirmation method that triggers the execution of the confirmationHandler.
If this method is not implemented clicks will be handled without confirmation.
- (BOOL)shouldConfirmClick:(CHBClickEvent *)event confirmationHandler:(void(^)(BOOL))confirmationHandler;

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: Implement to be notified of 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.
- (void)didClickAd:(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: Implement to be 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.
- (void)didFinishHandlingClick:(CHBClickEvent *)event error:(nullable CHBClickError *)error;

Description: Called after an ad is dismissed.
Parameter event: A dismiss event with info related to the dismissed ad.
Discussion: Implement to be notified of when an ad is no longer displayed.
- (void)didDismissAd:(CHBDismissEvent *)event;

 
Don’t make cache requests inside a didCacheAd:error or your app may enter an infinite loop under some conditions like having connectivity-issues and crash.
▲ Back to top

Description: Called after a cache call, either if an ad has been loaded from the Chartboost servers and cached, or tried to but failed.
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: Implement to be notified of when an ad is ready to be shown after the cache method has been called.
- (void)didCacheAd:(CHBCacheEvent *)event error:(nullable CHBCacheError *)error

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.
Discussion: Implement to be notified of when an ad is about to be presented.
- (void)willShowAd:(CHBShowEvent *)event;

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: Implement to be notified of when the ad presentation process has finished.
- (void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error;

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 is YES. It takes a BOOL 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 the confirmationHandler 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 the confirmationHandler.
Discussion: If you return YES it is your responsibility to implement some confirmation method that triggers the execution of the confirmationHandler.
If this method is not implemented clicks will be handled without confirmation.
- (BOOL)shouldConfirmClick:(CHBClickEvent *)event confirmationHandler:(void(^)(BOOL))confirmationHandler;

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: Implement to be notified of 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.
- (void)didClickAd:(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: Implement to be 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.
- (void)didFinishHandlingClick:(CHBClickEvent *)event error:(nullable CHBClickError *)error;

Description: Called after an ad is dismissed.
Parameter event: A dismiss event with info related to the dismissed ad.
Discussion: Implement to be notified of when an ad is no longer displayed.
- (void)didDismissAd:(CHBDismissEvent *)event;

Description: Called when a rewarded ad has completed playing.
Parameter event: A reward event with info related to the ad and the reward.
Discussion: Implement to be notified when a reward is earned.
- (void)didEarnReward:(CHBRewardEvent *)event;

Don’t make cache requests inside a didCacheAd:error or your app may enter an infinite loop under some conditions like having connectivity-issues and crash.
 
▲ Back to top

// Called after a cache call, either if an ad has been loaded from the Chartboost servers and cached, or tried to but failed.
- (void)didCacheAd:(CHBCacheEvent *)event error:(nullable CHBCacheError *)error

// Called after a showFromViewController: call, right before an ad is presented.
- (void)willShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error;

// Called after a showFromViewController: call, either if the ad has been presented and an ad impression logged, or if the operation failed.
- (void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error;

// Called whenever the user clicks an ad to give a chance to the developer to present a confirmation gate before the click is handled.
- (BOOL)shouldConfirmClick:(CHBClickEvent *)event confirmationHandler:(void(^)(BOOL))confirmationHandler;

// Called after an ad has been clicked.
- (void)didClickAd:(CHBClickEvent *)event error:(nullable CHBClickError *)error;<

// Called when the link viewer presented as result of an ad click has been dismissed.
- (void)didFinishHandlingClick:(CHBClickEvent *)event error:(nullable CHBClickError *)error;
Learn more about Chartboost banner ads here.
 
▲ Back to top

// Called after the App Store sheet is dismissed, when displaying the embedded app sheet.
- (void)didCompleteAppStoreSheetFlow;

// Called after a click is registered, but the user is not forwarded to the App Store.
- (void)didFailToRecordClick:(CBLocation)location
                   withError:(CBClickError)error;

//Called after the SDK has been successfully initialized and video prefetching has been completed
- (void)didInitialize:(BOOL)status;
Don’t make cache or show calls inside didFailToLoad delegates or the universe will implode.
 
▲ Back to top

// Decide if Chartboost SDK should block for an age gate.
+ (void)setShouldPauseClickForConfirmation:(BOOL)shouldPause;

// Called if Chartboost SDK pauses click actions awaiting confirmation from the user. Use
// to implement an age gate in your game.
- (void)didPauseClickForConfirmation;

// Confirm if an age gate passed or failed. When specified Chartboost will wait for
// this call before showing the IOS App Store.
+ (void)didPassAgeGate:(BOOL)pass;
Don’t make cache or show calls inside didFailToLoad delegates or the universe will implode.
 
▲ Back to top