‹ Chartboost Doc Home

Chartboost Integration Guide

For the C++ version of cocos2d-x v3.x - (all other versions)

Integration

Open a terminal and use the following command to install the SDKBOX Chartboost plugin. Make sure you setup the SDKBOX installer correctly.

$ sdkbox import chartboost

Important Notice

Please make sure the following settings in your project for plugin to function correctly.

Disable App Transport Security

Adding the following entry to the info.plist file:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

It should look something like this:

Disable Bitcode support

You have to turn off Bitcode support. If you don't cocos2d-x will fail to build.

Set your game requires full screen

If your game doesn't support all screen orientations you will need to check Requires full screen in Xcode. If you do not, your app will fail Apple's submission process.

Whitelist canOpenURL function

This depends on what plugins are in your project. You may need to add the required entry to the info.plist, under LSApplicationQueriesSchemes.

Follow this link

JSON Configuration

SDKBOX Installer will automatically inject a sample configuration to your sdkbox_config.json, that you have to modify it before you can use it for your own app

Here is an example of the Chartboost configuration, you need to replace <CHARTBOOST ID> and <CHARTBOOST SIGNATURE> items with your specific Chartboost account information.

"Chartboost":{
    "id":"<CHARTBOOST ID>",
    "signature":"<CHARTBOOST SIGNATURE>",
    "ads":{
        "Default":{
            "type":"interstitial"
        },
        "Level Complete":{
            "type":"rewarded_video"
        },
        "MoreApp":{
            "type":"more_app"
        }
    }
}

Usage

Initialize Chartboost

Initialize the plugin where appropriate in your code. We recommend to do this in the AppDelegate::applicationDidFinishLaunching() or AppController:didFinishLaunchingWithOptions(). Make sure to include the appropriate headers:

#include "PluginChartboost/PluginChartboost.h"
AppDelegate::applicationDidFinishLaunching()
{
     sdkbox::PluginChartboost::init();
}

Showing Ads

Display an ad where ever you want from your code:

// To use the Chartboost predefined locations
sdkbox::PluginChartboost::show(sdkbox::CB_Location_Default);
// To use customized location
sdkbox::PluginChartboost::show("your_ad_name");

Catch Chartboost events (optional)

This allows you to catch the Chartboost events so that you can perform operations such as providing player rewards for watching the video.

#include "PluginChartboost/PluginChartboost.h"
class MyClass : public sdkbox::ChartboostListener
{
public:
    void onChartboostCached(const std::string& name);
    bool onChartboostShouldDisplay(const std::string& name);
    void onChartboostDisplay(const std::string& name);
    void onChartboostDismiss(const std::string& name);
    void onChartboostClose(const std::string& name);
    void onChartboostClick(const std::string& name);
    void onChartboostReward(const std::string& name, int reward);
    void onChartboostFailedToLoad(const std::string& name, sdkbox::CB_LoadError e);
    void onChartboostFailToRecordClick(const std::string& name, sdkbox::CB_ClickError e);
    void onChartboostConfirmation();
    void onChartboostCompleteStore();
};
sdkbox::PluginChartboost::setListener(this);

API Reference

Methods

static void init ( ) ;

initialize the plugin instance.

static void show ( const std::string & name ) ;

show ad by specifying ad name.

static void setListener ( ChartboostListener * listener ) ;

creates the an optional listener.

static ChartboostListener * getListener ( ) ;
static void removeListener ( ) ;

removed the listener.

static bool isAnyViewVisible ( ) ;

check to see if any views are visible.

static bool isAvailable ( const std::string & name ) ;

is the specified ad available?

static void cache ( const std::string & name ) ;
static void setAutoCacheAds ( bool shouldCache ) ;

set to enable and disable the auto cache feature (Enabled by default).

static bool getAutoCacheAds ( ) ;

get the current auto cache behavior (Enabled by default).

static void closeImpression ( ) ;

close any visible Chartboost impressions (interstitials, more apps, rewarded video, etc..) and the loading view (if visible).

static void setStatusBarBehavior ( CB_StatusBarBehavior behavior ) ;

set to control how the fullscreen ad units should interact with the status bar. (CBStatusBarBehaviorIgnore by default).

static void didPassAgeGate ( bool pass ) ;

confirm if an age gate passed or failed. When specified Chartboost will wait for call before showing the IOS App Store.

static void setShouldPauseClickForConfirmation ( bool shouldPause ) ;

decide if Chartboost SDK should block for an age gate.

static bool handleOpenURL ( const std::string & url ,
                            const std::string & sourceApp ) ;

opens a "deep link" URL for a Chartboost Custom Scheme.

static void setCustomID ( const std::string & customID ) ;

set a custom identifier to send in the POST body for all Chartboost API server requests.

static std::string getCustomID ( ) ;

get the current custom identifier being sent in the POST body for all Chartboost API server requests.

static void setShouldRequestInterstitialsInFirstSession ( bool shouldRequest ) ;

decide if Chartboost SDK should show interstitials in the first session.

static void setShouldDisplayLoadingViewForMoreApps ( bool shouldDisplay ) ;

decide if Chartboost SDK should show a loading view while preparing to display the "more applications" UI.

static void setShouldPrefetchVideoContent ( bool shouldPrefetch ) ;

decide if Chartboost SDK will attempt to fetch videos from the Chartboost API servers.

Listeners

void onChartboostCached ( const std::string & name );

there is cached content

bool onChartboostShouldDisplay ( const std::string & name );

should Chartboost display

void onChartboostDisplay ( const std::string & name );

Charboost ad has displayed

void onChartboostDismiss ( const std::string & name );

Chartboost ad has been dismissed

void onChartboostClose ( const std::string & name );

Chartboost is not running

void onChartboostClick ( const std::string & name );

Chartboost ad was clicked on

void onChartboostReward ( const std::string & name , int reward );

Chartboost reward was given

void onChartboostFailedToLoad ( const std::string & name , CB_LoadError e );

Chartboost failed to load

void onChartboostFailToRecordClick ( const std::string & name ,
                                     CB_ClickError e );

Chartboost failed to record click

void onChartboostConfirmation ( );

Chartboost confirmation

void onChartboostCompleteStore ( );

Chartboost complete store

Manual Integration

If the SDKBOX Installer fails to complete successfully, it is possible to integrate SDKBOX manually. If the installer complete successfully, please do not complete anymore of this document. It is not necessary.

These steps are listed last in this document on purpose as they are seldom needed. If you find yourself using these steps, please, after completing, double back and re-read the steps above for other integration items.

Manual Integration For iOS

Drag and drop the following frameworks from the plugins/ios folder of the Chartboost bundle into your Xcode project, check Copy items if needed when adding frameworks:

sdkbox.framework

PluginChartboost.framework

Chartboost.framework

The above frameworks depend upon other frameworks. You also need to add the following system frameworks, if you don't already have them:

Security.framework

StoreKit.framework

Foundation.framework

CoreGraphics.framework

UIKit.framework

AdSupport.framework

Manual Integration For Android

SDKBOX supports three different kinds of Android projects command-line, eclipse and Android Studio.

Copy Files

Copy the following jar files from plugin/android/libs folder of this bundle into your project’s /libs folder.

chartboost.jar

PluginChartboost.jar

sdkbox.jar

Copy jni libs

Copy and overwrite all the folders from plugin/android/jni to your <project_root>/jni/ directory.

Note: sdkbox link with gnustl by default, if your project link with c++static please replace the files in <project_root>/jni/<plugin_name>/libs with files in <project_root>/jni/<plugin_name>/libs_c++_static folder

Edit AndroidManifest.xml

Include the following permissions above the application tag:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

To enable hardware acceleration in your application tag. This tag is optional on newer SDK versions and doesn't work on version 2.3.3.

<android:hardwareAccelerated="true" />

Edit Android.mk

Edit <project_root>/jni/Android.mk to:

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginChartboost
LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox

Add a call to:

$(call import-add-path,$(LOCAL_PATH))

before any import-module statements.

Add additional import-module statements at the end:

$(call import-module, ./sdkbox)
$(call import-module, ./pluginchartboost)

This means that your ordering should look similar to this:

$(call import-add-path,$(LOCAL_PATH))
$(call import-module, ./sdkbox)
$(call import-module, ./pluginchartboost)

Note: It is important to make sure these statements are above the existing $(call import-module,./prebuilt-mk) statement, if you are using the pre-built libraries.

Modify Application.mk (Cocos2d-x v3.0 to v3.2 only)

Edit <project_root>/jni/Application.mk to make sure APP_STL is defined correctly. If Application.mk contains APP_STL := c++_static, it should be changed to:

APP_STL := gnustl_static

Modify Cocos2dxActivity.java

Note: When using Cocos2d-x from source, different versions have Cocos2dxActivity.java in a different location. One way to find the location is to look in proj.android/project.properties. Example: android.library.reference.1=../../cocos2d-x/cocos/platform/android/java

In this case, Cocos2dxActivity.java should be located at:

../../cocos2d-x/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java
import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
onLoadNativeLibraries();
SDKBox.init(this);
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
          }
    }
    @Override
    protected void onStart() {
          super.onStart();
          SDKBox.onStart();
    }
    @Override
    protected void onStop() {
          super.onStop();
          SDKBox.onStop();
    }
    @Override
    protected void onResume() {
          super.onResume();
          SDKBox.onResume();
    }
    @Override
    protected void onPause() {
          super.onPause();
          SDKBox.onPause();
    }
    @Override
    public void onBackPressed() {
          if(!SDKBox.onBackPressed()) {
            super.onBackPressed();
          }
    }

Proguard (optional)

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# chartboost
-keep class com.chartboost.** { *; }
-dontwarn com.chartboost.**


# cocos2d-x
-keep public class org.cocos2dx.** { *; }
-dontwarn org.cocos2dx.**
-keep public class com.chukong.** { *; }
-dontwarn com.chukong.**

# google play service
-keep public class com.google.android.gms.** { public *; }
-dontwarn com.google.android.gms.**

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

#sdkbox
-keep class com.sdkbox.** { *; }
-dontwarn com.sdkbox.**

Note: Proguard only works with Release builds (i.e cocos run -m release) debug builds do not invoke Proguard rules.

Notice

SDKBox Chartboost v2.2.5.0+ android Required:

  1. Build SDK Version - 23
  2. Compile SDK Version - 23

if you get miss HttpClient error when set build sdk to 23:

  1. if use eclipse, copy $ANDROID_SDK_ROOT/platforms/android-23/optional/org.apache.http.legacy.jar to your project libs folder
  2. if use android studio, add this to your gradle:
android {
    useLibrary 'org.apache.http.legacy'
}