‹ InMobi Doc Home

InMobi Integration Guide

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

Integration

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

$ sdkbox import inmobi

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.

JSON Configuration

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

Here is an example of the InMobi configuration, you need to replace <account_id> item with your specific InMobi account information.

"InMobi":{
    "interstitial_placement_id": "1449919424310",       //interstitial id
    "account_id": "922cc696d9fa475097651b5cad78567d", 
    "banner_h": 50,                                     //banner height
    "banner_placement_id": "1447081423897"              //remove if needn't
}

Usage

Initialize InMobi

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 "PluginInMobi/PluginInMobi.h"
AppDelegate::applicationDidFinishLaunching()
{
     sdkbox::PluginInMobi::init();
}

Show interstitial

After initialization you can begin to use the InMobi functionality:

// Manually Loading Ads
sdkbox::PluginInMobi::loadInterstitial();

if (sdkbox::PluginInMobi::isInterstitialReady()) {
    CCLOG("Plugin InMobi interstitial ad is ready");
    sdkbox::PluginInMobi::showInterstitial();
} else {
    CCLOG("Plugin InMobi interstitial ad is not ready");
}

Set Log level

You can set log level with follow function

sdkbox::PluginInMobi::setLogLevel(sdkbox::PluginInMobi::SBIMSDKLogLevel::kIMSDKLogLevelDebug);

Set user data

You can use following functions to set user data

sdkbox::PluginInMobi::addIdForType("test", sdkbox::PluginInMobi::SBIMSDKIdType::kIMSDKIdTypeLogin);
sdkbox::PluginInMobi::removeIdType(sdkbox::PluginInMobi::SBIMSDKIdType::kIMSDKIdTypeLogin);
sdkbox::PluginInMobi::setAge(18);
sdkbox::PluginInMobi::setAreaCode("900");
sdkbox::PluginInMobi::setAgeGroup(sdkbox::PluginInMobi::SBIMSDKAgeGroup::kIMSDKAgeGroupBetween18And20);
sdkbox::PluginInMobi::setYearOfBirth(1989);
sdkbox::PluginInMobi::setEducation(sdkbox::PluginInMobi::SBIMSDKEducation::kIMSDKEducationHighSchoolOrLess);
sdkbox::PluginInMobi::setEthnicity(sdkbox::PluginInMobi::SBIMSDKEthnicity::kIMSDKEthnicityHispanic);
sdkbox::PluginInMobi::setGender(sdkbox::PluginInMobi::SBIMSDKGender::kIMSDKGenderMale);
sdkbox::PluginInMobi::setHouseholdIncome(sdkbox::PluginInMobi::SBIMSDKHouseholdIncome::kIMSDKHouseholdIncomeBelow5kUSD);
sdkbox::PluginInMobi::setIncome(4500);
sdkbox::PluginInMobi::setInterests("game");
sdkbox::PluginInMobi::setLanguage("en-us");
sdkbox::PluginInMobi::setLocation("cd", "sc", "usa");
sdkbox::PluginInMobi::setLocation(102, 348);
sdkbox::PluginInMobi::setNationality("nationality");
sdkbox::PluginInMobi::setPostalCode("618000");

Catch InMobi events (optional)

This allows you to catch the InMobi events so that you can perform operations based upon responses. A simple example might look like this:

#include "PluginInMobi/PluginInMobi.h"
class MyClass : public sdkbox::InMobiListener {
public:
    void bannerDidFinishLoading() {
        CCLOG("bannerDidFinishLoading");
    };
    void bannerDidFailToLoadWithError(sdkbox::PluginInMobi::SBIMStatusCode code, const std::string& description) {
        CCLOG("bannerDidFailToLoadWithError status:%d, desc:%s", code, description.c_str());
    };

    void bannerDidInteractWithParams(const std::map<std::string, std::string>& params) {
        CCLOG("bannerDidInteractWithParams");
    };

    void userWillLeaveApplicationFromBanner() {
        CCLOG("userWillLeaveApplicationFromBanner");
    };

    void bannerWillPresentScreen() {
        CCLOG("bannerWillPresentScreen");
    };

    void bannerDidPresentScreen() {
        CCLOG("bannerDidPresentScreen");
    };

    void bannerWillDismissScreen() {
        CCLOG("bannerWillDismissScreen");
    };

    void bannerDidDismissScreen() {
        CCLOG("bannerDidDismissScreen");
    };

    void bannerRewardActionCompletedWithRewards(const std::map<std::string, std::string>& rewards) {
        CCLOG("bannerRewardActionCompletedWithRewards");
    };

    void interstitialDidFinishLoading() {
        CCLOG("interstitialDidFinishLoading");
    };

    void interstitialDidFailToLoadWithError(sdkbox::PluginInMobi::SBIMStatusCode code, const std::string& description) {
        CCLOG("interstitialDidFailToLoadWithError status:%d, desc:%s", code, description.c_str());
    };

    void interstitialWillPresent() {
        CCLOG("interstitialWillPresent");
    };

    void interstitialDidPresent() {
        CCLOG("interstitialDidPresent");
    };

    void interstitialDidFailToPresentWithError(sdkbox::PluginInMobi::SBIMStatusCode code, const std::string& description) {
        CCLOG("interstitialDidFailToPresentWithError");
    };

    void interstitialWillDismiss() {
        CCLOG("interstitialWillDismiss");
    };

    void interstitialDidDismiss() {
        CCLOG("interstitialDidDismiss");
    };

    void interstitialDidInteractWithParams(const std::map<std::string, std::string>& params) {
        CCLOG("interstitialDidInteractWithParams");
    };

    void interstitialRewardActionCompletedWithRewards(const std::map<std::string, std::string>& rewards) {
        CCLOG("interstitialRewardActionCompletedWithRewards");
    };

    void userWillLeaveApplicationFromInterstitial() {
        CCLOG("userWillLeaveApplicationFromInterstitial");
    };
};
sdkbox::PluginInMobi::setListener(this);

API Reference

Methods

static bool init ( ) ;

initialize the plugin instance.

static void setListener ( InMobiListener * listener ) ;

Set listener to listen for inmobi events

static InMobiListener * getListener ( ) ;

Get the listener

static void removeListener ( ) ;

Remove the listener, and can't listen to events anymore

static std::string getVersion ( ) ;

Use this to get the version of the SDK. @return The version of the SDK.

static void setLogLevel ( SBIMSDKLogLevel desiredLogLevel ) ;

Set the log level for SDK's logs @param desiredLogLevel The desired level of logs.

static void addIdForType ( const std::string & identifier ,
                           SBIMSDKIdType type ) ;

Register a user specific id with the SDK @param identifier The user Id. @param type The user Id type.

static void removeIdType ( SBIMSDKIdType type ) ;

Deregister a particular set of Ids @param type The user Id type.

static void setAge ( int age ) ;

Provide the user's age to the SDK for targeting purposes. @param age The user's age.

static void setAreaCode ( const std::string & areaCode ) ;

Provide the user's area code to the SDK for targeting purposes. @param areaCode The user's area code.

static void setAgeGroup ( SBIMSDKAgeGroup ageGroup ) ;

Provide the user's age group to the SDK for targeting purposes. @param ageGroup The user's age group.

static void setYearOfBirth ( int yearOfBirth ) ;

Provide a user's date of birth to the SDK for targeting purposes. @param dateOfBirth The user's date of birth.

static void setEducation ( SBIMSDKEducation education ) ;

Provide the user's education status to the SDK for targeting purposes. @param education The user's education status.

static void setEthnicity ( SBIMSDKEthnicity ethnicity ) ;

Provide the user's ethnicity to the SDK for targeting purposes. @param ethnicity The user's ethnicity.

static void setGender ( SBIMSDKGender gender ) ;

Provide the user's gender to the SDK for targeting purposes. @param gender The user's gender.

static void setHouseholdIncome ( SBIMSDKHouseholdIncome income ) ;

Provide the user's household income to the SDK for targeting purposes. @param income The user's household income.

static void setIncome ( unsigned int income ) ;

Provide the user's income to the SDK for targeting purposes. @param income The user's income.

static void setInterests ( const std::string & interests ) ;

Provide the user's interests to the SDK for targeting purposes. @param interests The user's interests.

static void setLanguage ( const std::string & language ) ;

Provide the user's preferred language to the SDK for targeting purposes. @param language The user's language.

static void setLocation ( const std::string & city ,
                          const std::string & state ,
                          const std::string & country ) ;

Provide the user's location to the SDK for targeting purposes. @param city The user's city. @param state The user's state. @param country The user's country.

static void setLocation ( double latitude , double longitude ) ;

Provide the user's location to the SDK for targeting purposes. @param location: The location of the user

static void setNationality ( const std::string & nationality ) ;

Provide the user's nationality to the SDK for targeting purposes. @param nationality The user's nationality.

static void setPostalCode ( const std::string & postalcode ) ;

Provide the user's postal code to the SDK for targeting purposes. @param postalcode The user's postalcode.

static void shouldAutoRefresh ( bool refresh ) ;

Control if the banner should auto-refresh ad content.

static void setRefreshInterval ( int interval ) ;

Specify the refresh interval for the banner ad.

static void loadBanner ( ) ;

Submit a request to load banner ad content.

static void disableHardwareAccelerationForBanner ( ) ;

Turn off hardware acceleration on the underlying views. vaild on android

static void setBannerAnimationType ( SBIMBannerAnimationType animationType ) ;

Set the animation preference on the banner views during ad refresh.

static void setBannerExtras ( const std::map <std::string ,
                              std::string> & extras ) ;

Set any additional custom parameters that will be sent in the ad request.

static void setBannerKeywords ( const std::string & keywords ) ;

Set comma delimited keywords for targeting purpose

static void loadInterstitial ( ) ;

Submit a request to load interstitial ad content.

static bool isInterstitialReady ( ) ;

Returns true if the interstitial was loaded successfully and in ready to be shown.

static void showInterstitial ( ) ;

Displays the interstitial on the screen

static void showInterstitial ( SBIMInterstitialAnimationType type ) ;

Displays the interstitial on the screen valid on ios

static void showInterstitial ( int enterAnimationResourcedId ,
                               int exitAnimationResourceId ) ;

Displays the interstitial on the screen valid on android

static void disableHardwareAccelerationForInterstitial ( ) ;

Disable hardware acceleration on the underlying views. valid on android

static void setInterstitialExtras ( const std::map <std::string ,
                                    std::string> & extras ) ;

Set any additional custom parameters that will be sent in the ad request.

static void setInterstitialKeywords ( const std::string & keywords ) ;

Set comma delimited keywords for targeting purpose

Listeners

void bannerDidFinishLoading ( ) {

Notifies the delegate that the banner has finished loading

void bannerDidFailToLoadWithError ( PluginInMobi::SBIMStatusCode code ,
                                    const std::string & description ) {

Notifies the delegate that the banner has failed to load with some error.

void bannerDidInteractWithParams ( const std::map <std::string ,
                                   std::string> & params ) {

Notifies the delegate that the banner was interacted with.

void userWillLeaveApplicationFromBanner ( ) {

Notifies the delegate that the user would be taken out of the application context.

void bannerWillPresentScreen ( ) {

Notifies the delegate that the banner would be presenting a full screen content.

void bannerDidPresentScreen ( ) {

Notifies the delegate that the banner has finished presenting screen.

void bannerWillDismissScreen ( ) {

Notifies the delegate that the banner will start dismissing the presented screen.

void bannerDidDismissScreen ( ) {

Notifies the delegate that the banner has dismissed the presented screen.

void bannerRewardActionCompletedWithRewards ( const std::map <std::string ,
                                              std::string> & rewards );

Notifies the delegate that the user has completed the action to be incentivised with.

void interstitialDidFinishLoading ( ) {

Notifies the delegate that the interstitial has finished loading

void interstitialDidFailToLoadWithError ( PluginInMobi::SBIMStatusCode code ,
                                          const std::string & description ) {

Notifies the delegate that the interstitial has failed to load with some error.

void interstitialWillPresent ( ) {

Notifies the delegate that the interstitial would be presented.

void interstitialDidPresent ( ) {

Notifies the delegate that the interstitial has been presented.

void interstitialDidFailToPresentWithError ( PluginInMobi::SBIMStatusCode code ,
                                             const std::string & description ) {

Notifies the delegate that the interstitial has failed to present with some error.

void interstitialWillDismiss ( ) {

Notifies the delegate that the interstitial will be dismissed.

void interstitialDidDismiss ( ) {

Notifies the delegate that the interstitial has been dismissed.

void interstitialDidInteractWithParams ( const std::map <std::string ,
                                         std::string> & params ) {

Notifies the delegate that the interstitial has been interacted with.

void interstitialRewardActionCompletedWithRewards ( const std::map <std::string ,
                                                    std::string> & rewards );

Notifies the delegate that the user has performed the action to be incentivised with.

void userWillLeaveApplicationFromInterstitial ( ) {

Notifies the delegate that the user will leave application context.

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 InMobi bundle into your Xcode project, check Copy items if needed when adding frameworks:

sdkbox.framework

PluginInMobi.framework

add the following system frameworks, if you don't already have them:

AdSupport.framework

AudioToolbox.framework

AVFoundation.framework

CoreLocation.framework

CoreTelephony.framework

EventKit.framework

EventKitUI.framework

MediaPlayer.framework

MessageUI.framework

Security.framework

Social.framework

StoreKit.framework

SystemConfiguration.framework

UIKit.framework

SafariServices.framework

GameController.framework

libsqlite3.0.tbd

libc++.tbd

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 proj.android/libs folder.

InMobi-5.1.0.jar

PluginInMobi.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

<!--Mandatory permissions to receive ads-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<!--Recommended permissions to receive brand‐centric ads with interactive functionality for better eCPMs-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<!--Required Activity for rendering ads in the embedded browser-->
<activity android:name="com.inmobi.rendering.InMobiAdActivity"
            android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:hardwareAccelerated="true" />


<!--Required Receiver for enhanced targeting for better ads.-->

<receiver android:name="com.inmobi.commons.core.utilities.uid.ImIdShareBroadCastReceiver"
            android:enabled="true"
            android:exported="true" >
    <intent-filter>
       <action android:name="com.inmobi.share.id" />
    </intent-filter>
</receiver>

<service android:enabled="true" android:name="com.inmobi.signals.activityrecognition.ActivityRecognitionManager" />

<!--Required for Google Play Services-->

<meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

Edit Android.mk

Edit proj.android/jni/Android.mk to:

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += android_native_app_glue
LOCAL_LDLIBS += -landroid
LOCAL_LDLIBS += -llog
LOCAL_WHOLE_STATIC_LIBRARIES += PluginInMobi
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, ./plugininmobi)

This means that your ordering should look similar to this:

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

Edit Application.mk

Edit proj.android/jni/Application.mk to:

Add APP_PATFORM version requirements:

APP_PLATFORM := android-9

Modify .java

import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  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();
          }
    }

Manual Integration for Google Play Services SDK (dependent library only)

Suggestion

Please try the sdkbox installer first. It will do all the following step for you automatically.

$ sdkbox import googleplayservices

Modify project.properties

An Android Library Reference for Google Play Services is required. The path will be different depending upon your setup. Also, this is an additional download that does not come as part of a standard install. To install use the sdk installer and choose extras->google play services. Here is an example of what this line could look like:

android.library.reference.1=
../android/sdk.latest/extras/google/google_play_services/libproject/
google-play-services_lib

Note: if you already have an android.library.reference.1 you can add another by incrementing the number as android.library.reference.2, etc.

Integration manually

We make a lite version of Google Play Services, the project repo is https://github.com/darkdukey/Google-Play-Service-Lite

Copy Files

Copy the gps folder from plugin folder of this bundle into your project’s /libs folder.

Modify files for Eclipse

  1. Modify project.properties
# For source project
android.library.reference.2=../cocos2d/cocos/platform/android/java/libs/gps/

# Or
# For framework project
android.library.reference.1=libs/gps/

Modify files for Android Studio

1. Modify cocos2d/cocos/platform/android/libcocos2dx/build.gradle
 dependencies {
+    compile project(':gps')
     compile fileTree(dir: '../java/libs', include: ['*.jar'])
 }
2. Modify proj.android-studio/app/project.properties
 # Project target.
 target=android-10
+android.library.reference.1=../cocos2d/cocos/platform/android/java/libs/gps/
3. Modify proj.android-studio/settings.gradle
 project(':libcocos2dx').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/libcocos2dx')
 include ':your_project_name'
 project(':your_project_name').projectDir = new File(settingsDir, 'app')
+
+include ':gps'
+project(':gps').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/java/libs/gps')

Proguard (optional)

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


# 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 public 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.