iOS SDK 8.1.x Upgrade

Initialization

Chartboost initialization method:

startWithAppId:appSignature:delegate:

is replaced by:

startWithAppId:appSignature:completion:

With the new method, instead of implementing -[ChartboostDelegate didInitialize:] to get notified of when the SDK is done initializing, you pass a block as the completion parameter:

Instead of:

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Chartboost startWithAppId:YOUR_CHARTBOOST_APP_ID
appSignature:YOUR_CHARTBOOST_APP_SIG
delegate:self];
return YES;
}
- (void)didInitialize:(BOOL)status {
// Chartboost finished initializing!
}

You do:

 - (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Chartboost startWithAppId:YOUR_CHARTBOOST_APP_ID
appSignature:YOUR_CHARTBOOST_APP_SIG<
completion:^(BOOL success) {
// Chartboost finished initializing!
}];
return YES;
}
Interstitial and Rewarded Ads

We have introduced CHBInterstitial and CHBRewarded classes that replace all the ad-related methods in Chartboost.h and ChartboostDelegate.h.

Before, you would cache and show an interstitial ad like this:

[Chartboost cacheInterstitial:CBLocationDefault];
// ...
if ([Chartboost hasInterstitial]) {
[Chartboost showInterstitial:CBLocationDefault];
}

With the new CHBInterstitial class:

 CHBInterstitial *interstitial = [[CHBInterstitial alloc] initWithLocation:CBLocationDefault delegate:self];
[interstitial cache];
// ...
if (interstitial.isCached) {
[interstitial showFromViewController:self];
} 

The main differences between the old and the new ad APIs are:

  • You create the new interstitial or rewarded ad and keep a strong reference to it until you don’t need it anymore. This means you should assign the created ad to a property in your view controller or other object.
  • New ads have their own delegate, they no longer share the ChartboostDelegate.
  • Showing a non-cached ad will fail immediately for new ads. Old ads would wait until the ad was cached before proceeding with the show request and even trigger the cache request automatically when asked to show, but this is not the case for the new ad types.

How to handle a show request failure for a non-cached ad:

    1. Check if the ad is cached before calling showFromViewController: 

       if (self.rewardedAd.isCached) {
      [self.rewardedAd showFromViewController:self];
      } else {
      // ad is not ready to be shown!
      }

    2. Implement the didShowAd:error: delegate method and check for the CHBShowErrorCodeNoCachedAderror code:

      // ...
      [self.rewardedAd showFromViewController:self];
      }
      - (void)didShowAd:(CHBShowEvent *)event error:(CHBShowError *)error {
      if (error.code == CHBShowErrorCodeNoCachedAd) {
      // ad is not ready to be shown!
      }
      }

Ad Delegates

We’ve seen how to create, cache and show ads. In order to get notified of relevant ad events you’ll need to implement CHBInterstitialDelegate and CHBRewardedDelegate methods, instead of the old ChartboostDelegate.

In this table we show the correspondence between the old ChartboostDelegate and the new ad delegate methods:

 
ChartboostDelegate CHBInterstitialDelegate / CHBRewardedDelegate
customAgeGateView No counterpart.
shouldRequestInterstitial: No counterpart. To prevent the SDK from loading ads don’t call the cache method.
shouldDisplayInterstitial: shouldDisplayRewardedVideo: No counterpart. To prevent the SDK from showing ads don’t call the show method.
didDisplayInterstitial: didDisplayRewardedVideo: didShowAd:error: (with a nil error).
didCacheInterstitial: didCacheRewardedVideo: didCacheAd:error (with a nil error).
didFailToLoadInterstitial:withError: didFailToLoadRewardedVideo:withError: Either: didCacheAd:error (with a non-nil error) or: didShowAd:error: (with a non-nil error) Depending on if the failure occurred while performing a cache or a show.
didFailToRecordClick:withError: didClickAd:error: (with a non-nil error)
didDismissInterstitial: didDismissRewardedVideo: didDismissAd:
didCloseInterstitial: didCloseRewardedVideo: No counterpart. Just use didDismissAd:
didClickInterstitial: didClickRewardedVideo: didClickAd:error: (with a nil error)
didCompleteRewardedVideo:withReward: didEarnReward:
willDisplayInterstitial: willDisplayVideo: willShowAd:
didCompleteAppStoreSheetFlow No direct counterpart. didFinishHandlingClick:error: is a more general version of this method, and will be called whenever the user goes back to the app after clicking the ad.
didPauseClickForConfirmation shouldConfirmClick:confirmationHandler: See section below for a detailed explanation.
Click confirmation / age gate

With the old Chartboost APIs, implementing an age gate that provides a confirmation step before handling an ad click would consist of:

  • Turning on the feature with a Chartboost method:

    [Chartboost setShouldPauseClickForConfirmation:YES];

  • Implementing the ChartboostDelegate method that tells when the age gate should be displayed:

    - (void)didPauseClickForConfirmation { // Show the age gate }

  • Calling this Chartboost method when the age gate has passed or failed to:

    [Chartboost didPassAgeGate:passed];

With the new ad APIs you just need to implement the CHBAdDelegate method (not implementing it will keep the feature turned off):

  - (BOOL)shouldConfirmClick:(CHBClickEvent *)event confirmationHandler:(void(^)(BOOL))confirmationHandler {
if (YOU_WANT_TO_ENABLE_AGE_GATE) {
// Present your age gate view
// When you have decided if the age gate has passed, call:
// confirmationHandler(AGE_GATE_PASSED);
return YES;
} else {
return NO;
}
}

Auto Cache

Old ads would by default automatically cache a new ad when shown.

This feature could be turned off with:

+[Chartboost setAutoCacheAds:]

This is not available for the new ad types. If you want to implement a similar behavior you can do cache the ad yourself when it is dismissed, by implementing this CHBAdDelegate method:

- (void)didDismissAd:(CHBDismissEvent *)event { [event.ad cache]; }

Request Interstitial In First Session

The method:

+[Chartboost setShouldRequestInterstitialsInFirstSession:]

does not work with the new ad types and does not have a counterpart. If you want to prevent ads from showing on the first app run you should implement this behavior yourself by not calling Chartboost methods in that case.

Mediation Adapters

If you are writing an adapter between Chartboost SDK and some mediation SDK, instead of the old:

+[Chartboost setMediation:withLibraryVersion:adapterVersion:]

You should use the custom ad initializers defined in the Chartboost+Mediation.h file:

-[CHBInterstitial initWithLocation:mediation:delegate:]

-[CHBRewarded initWithLocation:mediation:delegate:]

-[CHBBanner initWithSize:location:mediation:delegate:]



Last Updated on March 2, 2020