Delegate Methods
Overview π
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.
- Determine when an ad is done loading and ready to be shown.
- Determine whether a user has clicked an ad or just closed it and react accordingly.
You can view the Chartboost iOS SDK methods at your disposal in the CHBAdDelegate.h header file in the Chartboost framework. You can see many of these methods in use within the Chartboost sample project.
All iOS 14 information can be found on Upgrading the SDK.
SDK Configuration Methods π
See SDK Configuration Methods.
Ad Delegate Setup π
In order to receive delegate method calls you need to set the adβs delegate:
-
var interstitial = CHBInterstitial(location: "Default", delegate: self) // now self will receive delegate calls for the methods it has implemented interstitial.delegate = anotherObject // now anotherObject will receive delegate calls for this ad instead of self -
CHBInterstitial *interstitial = [[CHBInterstitial alloc] initWithLocation:@"Default" delegate:self]; // now self will receive delegate calls for the methods it has implemented interstitial.delegate = anotherObject; // now anotherObject will receive delegate calls for this ad instead of self
Ad Identifier π
All the event objects passed as parameters in delegate method calls include an adID property. This is a string that uniquely identifies a cached ad and may assist in identifying faulty creatives when working with Chartboost.
Static & Video Interstitial Delegate Methods π
didCacheAd π
- 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
nilif the operation was successful. - Discussion: Get notified of when an ad is ready to be shown after the cache method has been called.
Example:
-
func didCacheAd(_ event: CHBCacheEvent, error: CHBCacheError?){ if let error = error { // Handle error. Maybe trigger a retry mechanism. } } -
- (void)didCacheAd:(CHBCacheEvent *)event error:(nullable CHBCacheError *)error { if (error) { // Handle error. Maybe trigger a retry mechanism. } }
didCacheAd:error or your app may enter an infinite loop which may cause, but not limited to, connectivity-issues and crashing.
willShowAd π
- 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: Get notified of when an ad is about to be presented.
Example:
-
func willShowAd(_ event: CHBShowEvent){ // Pause ongoing processes like video or gameplay. } -
- (void) willShowAd:(CHBShowEvent *)event { // Pause ongoing processes like video or gameplay. }
didShowAd π
- 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 when the ad presentation process has finished.
Example:
-
func didShowAd(_ event: CHBShowEvent, error: CHBShowError?){ if let error = error { // Handle error, possibly resuming processes paused in willShowAd } } -
- (void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error { if (error) { // Handle error, possibly resuming processes paused in willShowAd } }
didClickAd π
- 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
nilif the operation was successful. - Discussion: Get 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.
Example:
-
func didClickAd(_ event: CHBClickEvent, error: CHBClickError?) { if let error = error { // Handle error } } -
- (void)didClickAd:(CHBClickEvent *)event error:(nullable CHBClickError *)error { if (error) { // Handle error } }
didDismissAd π
- Description: Called after an ad is dismissed.
- Parameter Event: A dismiss event with info related to the dismissed ad.
- Discussion: Get notified of when an ad is no longer displayed.
Example:
-
func didDismissAd(_ event: CHBDismissEvent) { // Resume processes paused in willShowAd } -
- (void)didDismissAd:(CHBDismissEvent *)event { // Resume processes paused in willShowAd: }
didRecordImpression π
- Description: Called after an ad has recorded an impression.
- Parameter Event: An impression event with info related to the visible ad.
- Discussion: Implement to be notified of when an ad has recorded an impression. This method will be called once a valid impression is recorded after showing the ad.
Example:
-
func didRecordImpression(_ event: CHBImpressionEvent){ // Resume app gameplay state to reflect that the user has watched an ad } -
- (void)didRecordImpression:(CHBImpressionEvent *)event { // Resume app gameplay state to reflect that the user has watched an ad }
didExpireAd π
- Description: Called when a loaded ad has expired.
- Parameter Event: An expiration event with info related to the expired ad.
- Discussion: Implement to be notified of when an ad has expired. This method will be called if a loaded ad is not shown before a predetermined expiration interval. After expiration a new ad may be loaded.
Example:
-
func didExpireAd(_ event: CHBExpirationEvent) { // The cached ad has expired, cache a new one } -
- (void)didExpireAd:(CHBExpirationEvent *)event { // The cached ad has expired, cache a new one }
Rewarded video delegate methods: π
didCacheAd π
- 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
nilif the operation was successful. - Discussion: Get notified of when an ad is ready to be shown after the cache method has been called.
Example:
-
func didCacheAd(_ event: CHBCacheEvent, error: CHBCacheError?){ if let error = error { // Handle error. Maybe trigger a retry mechanism. } } -
- (void)didCacheAd:(CHBCacheEvent *)event error:(nullable CHBCacheError *)error { if (error) { // Handle error. Maybe trigger a retry mechanism. } }
willShowAd π
- 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: Get notified of when an ad is about to be presented.
Example:
-
func willShowAd(_ event: CHBShowEvent){ // Pause ongoing processes like video or gameplay. } -
- (void) willShowAd:(CHBShowEvent *)event { // Pause ongoing processes like video or gameplay. }
didShowAd π
- 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 let error = error { // Handle error, possibly resuming processes paused in willShowAd } } -
- (void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error { if (error) { // Handle error, possibly resuming processes paused in willShowAd } }
didClickAd π
- 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
nilif the operation was successful. - Discussion: Get notified of when an ad has been clicked. If the click does not result into the opening of a link, then an error will be provided explaining why.
Example:
-
func didClickAd(_ event: CHBClickEvent, error: CHBClickError?) { if let error = error { // Handle error } } -
- (void)didClickAd:(CHBClickEvent *)event error:(nullable CHBClickError *)error { if (error) { // Handle error } }
didDismissAd π
- Description: Called after an ad is dismissed.
- Parameter Event: A dismiss event with info related to the dismissed ad.
- Discussion: Get notified of when an ad is no longer displayed.
Example:
-
func didDismissAd(_ event: CHBDismissEvent) { // Resume processes paused in willShowAd } -
- (void)didDismissAd:(CHBDismissEvent *)event { // Resume processes paused in willShowAd: }
didEarnReward π
- Description: Called when a rewarded ad has completed playing.
- Parameter Event: A reward event with info related to the ad and the reward.
- Discussion: Get notified when a reward is earned.
Example:
-
func didEarnReward(_ event: CHBRewardEvent) { // Update app internal state to reflect the earned reward } -
- (void)didEarnReward:(CHBRewardEvent *)event { // Update app internal state to reflect the earned reward }
didRecordImpression π
- Description: Called after an ad has recorded an impression.
- Parameter Event: An impression event with info related to the visible ad.
- Discussion: Implement to be notified of when an ad has recorded an impression. This method will be called once a valid impression is recorded after showing the ad.
Example:
-
func didRecordImpression(_ event: CHBImpressionEvent){ // Resume app gameplay state to reflect that the user has watched an ad } -
- (void)didRecordImpression:(CHBImpressionEvent *)event { // Resume app gameplay state to reflect that the user has watched an ad }
didExpireAd π
- Description: Called when a loaded ad has expired.
- Parameter Event: An expiration event with info related to the expired ad.
- Discussion: Implement to be notified of when an ad has expired. This method will be called if a loaded ad is not shown before a predetermined expiration interval. After expiration a new ad may be loaded.
Example:
-
func didExpireAd(_ event: CHBExpirationEvent) { // The cached ad has expired, cache a new one } -
- (void)didExpireAd:(CHBExpirationEvent *)event { // The cached ad has expired, cache a new one }
didCacheAd:error or your app may enter an infinite loop which may cause, but not limited to, connectivity-issues and crashing.
Banner Delegate Methods π
didCacheAd π
- Parameter event: A cache event with info related to the cached ad.
- Parameter error: An error specifying the failure reason, or
nilif the operation was successful. - Discussion: Get notified of when an ad is ready to be shown after the cache method has been called.
Example:
-
func didCacheAd(_ event: CHBCacheEvent, error: CHBCacheError?){ if let error = error { // Handle error. Maybe trigger a retry mechanism. } } -
- (void)didCacheAd:(CHBCacheEvent *)event error:(nullable CHBCacheError *)error { if (error) { // Handle error. Maybe trigger a retry mechanism. } }
willShowAd π
- 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: Get notified of when an ad is about to be presented.
Example:
-
func willShowAd(_ event: CHBShowEvent){ // Pause ongoing processes like video or gameplay. } -
- (void) willShowAd:(CHBShowEvent *)event { // Pause ongoing processes like video or gameplay. }
didShowAd π
- 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
nilif the operation was successful. - Discussion: Get notified of when the ad presentation process has finished.
Example:
-
func didShowAd(_ event: CHBShowEvent, error: CHBShowError?){ if let error = error { // Handle error, possibly resuming processes paused in willShowAd } } -
- (void)didShowAd:(CHBShowEvent *)event error:(nullable CHBShowError *)error { if (error) { // Handle error, possibly resuming processes paused in willShowAd } }
didClickAd π
- 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
nilif the operation was successful. - Discussion: Get notified of when an ad has been clicked. If the click does not result into the opening of a link, then an error will be provided explaining why.
Example:
-
func didClickAd(_ event: CHBClickEvent, error: CHBClickError?) { if let error = error { // Handle error } } -
- (void)didClickAd:(CHBClickEvent *)event error:(nullable CHBClickError *)error { if (error) { // Handle error } }
didRecordImpression π
- Description: Called after an ad has recorded an impression.
- Parameter Event: An impression event with info related to the visible ad.
- Discussion: Implement to be notified of when an ad has recorded an impression. This method will be called once a valid impression is recorded after showing the ad.
Example:
-
func didRecordImpression(_ event: CHBImpressionEvent){ // Resume app gameplay state to reflect that the user has watched an ad } -
- (void)didRecordImpression:(CHBImpressionEvent *)event { // Resume app gameplay state to reflect that the user has watched an ad }
didExpireAd π
- Description: Called when a loaded ad has expired.
- Parameter Event: An expiration event with info related to the expired ad.
- Discussion: Implement to be notified of when an ad has expired. This method will be called if a loaded ad is not shown before a predetermined expiration interval. After expiration a new ad may be loaded.
Example:
-
func didExpireAd(_ event: CHBExpirationEvent) { // The cached ad has expired, cache a new one } -
- (void)didExpireAd:(CHBExpirationEvent *)event { // The cached ad has expired, cache a new one }