‹ PhunwareAds Doc Home

Phunware Integration Guide(Ads)

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

SDK Version

Integration

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

$ sdkbox import phunwareads

Important Notice

Please make sure the following settings in your project to make the plugin work well.

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 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 setting 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 sdkbox_config.json, that you have to modify it before you can use it for your own app

Here is an example of the PhunwareAds configuration.

"PhunwareAds":{
    "debug":true,
    "ads": {
        "banner":{
            "id":"7268",
            "type":"banner",
            "test_mode":true
        },
        "interstitial":{
            "id":"7271",
            "type":"interstitial"
        },
        "video":{
            "id":"22219",
            "type":"video"
        },
        "reward":{
            "id":"78393",
            "type":"reward"
        },
        "page":{
            "id":"76663",
            "type":"page"
        }
    }
}

Usage

Initialize PhunwareAds

sdkbox.PluginPhunwareAds:init()

Showing Ads

Display an ad where ever you want from your code:

// To use customized location
sdkbox.PluginPhunwareAds:show("your_ad_name")

Cache Ads

sdkbox.PluginPhunwareAds:cache("your_ad_name")

Hide Ads

sdkbox.PluginPhunwareAds:hide("your_ad_name")

Catch PhunwareAds events (optional)

This allows you to catch the PhunwareAds events so that you can perform operations such as providing player rewards for viewing ads.

sdkbox.PluginPhunwareAds:setListener(function(args)

    if "adLoaded" = args.event then
        print(args.event, args.name)
    elseif adFailed" = args.event then
        print(args.event, args.errorCode, args.msg)
    elseif adWillPresent" = args.event then
        print(args.event, args.name)
    elseif adDidPresent" = args.event then
        print(args.event, args.name)
    elseif adWillDissmiss" = args.event then
        print(args.event, args.name)
    elseif adDidDismiss" = args.event then
        print(args.event, args.name)
    elseif willLeaveApp" = args.event then
        print(args.event, args.name)
    elseif reward" = args.event then
        print(args.event, args.name, args.amount, args.currency)
    end

end)

API Reference

Methods

sdkbox.PluginPhunwareAds:init()

initialize the plugin instance.

sdkbox.PluginPhunwareAds:setListener(listener)

Set listener to listen for phunware events

sdkbox.PluginPhunwareAds:cache(name)

cache ad by specifying ad name, auto cache default.

sdkbox.PluginPhunwareAds:isAvailable(name)

is the specified ad available?

sdkbox.PluginPhunwareAds:show(name)

show ad by specifying ad name.

sdkbox.PluginPhunwareAds:hide(name)

hide ad by specifying ad name.

sdkbox.PluginPhunwareAds:setUserID(userID)

set user ID for rewarded video.

sdkbox.PluginPhunwareAds:getRemainingViews(name)

get remaining views of rewarded video.

sdkbox.PluginPhunwareAds:setCustomData(name, data)

set custom data of rewarded video

Listeners

adLoaded(name)

there is cached content

adFailed(name, errorCode, msg)

there is error when cache content

adWillPresent(name)

ad will present

adDidPresent(name)

ad did present

adWillDissmiss(name)

ad will dissmiss

adDidDismiss(name)

ad did dismiss

willLeaveApp(name)

will leave application

reward(name, amount, currency, customData)

reward user with specifying ad name

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 PhunwareAds bundle into your Xcode project

check Copy items if needed when adding frameworks:

sdkbox.framework

PluginPhunware.framework

PWCore.framework

PWAdvertising.framework

The above frameworks depend upon other frameworks. You also need to add the following system frameworks

if you don't already have them:

SystemConfiguration.framework

QuartsCore.framework

CoreTelephony.framework

MessageUI.framework

EventKit.framework

EventKitUI.framework

CoreMedia.framework

AVFoundation.framework

MediaPlayer.framework

AudioToolbox.framework

AdSupport.framework

StoreKit.framework

CoreLocation.framework

MobileCoreServices.framework

QuartzCore.framework

Security.framework

UIKit.framework

WebKit.framework

Copy all source and header files from plugin/luabindings/ to your projects Classes folder.

Add these same files, that you just copied, to Xcode by either dragging and dropping them into Xcode or by using File -> Add files to....

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.

phunwareads.jar

PluginPhunwareAds.jar

sdkbox.jar

Copy jni libs

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

Edit AndroidManifest.xml

Include the following permissions above the application tag:

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

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 project.properties

android.library.reference.1=libs/maas_ads

Edit Android.mk

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

Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:

LOCAL_WHOLE_STATIC_LIBRARIES += PluginPhunwareAds
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, ./pluginphunwareads)

This means that your ordering should look similar to this:

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

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

Copy all source and header files from plugin/luabindings/ to your projects Classes folder.

Add all .cpp files, that you just copied, to Android.mk in the LOCAL_SRC_FILES section. Example

LOCAL_SRC_FILES := hellocpp/main.cpp \
                ../../Classes/AppDelegate.cpp \
                ../../Classes/HelloWorldScene.cpp \
                                ../../Classes/NewSourceFile.cpp

Modify AppActivity.java

Plugin >= 2.4.0.3

  1. Find the AppActivity.java
find . -name "AppActivity.java"
  1. Replace extends Cocos2dxActivity with extends com.sdkbox.plugin.SDKBoxActivity

Example of the directory where the AppActivity.java file is located:

cpp
  - proj.android/src/org/cocos2dx/cpp/AppActivity.java
  - proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java
  - proj.android/app/src/org/cocos2dx/cpp/AppActivity.java ( from cocos2d-x 3.17)

lua
  - frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java
  - frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/lua/AppActivity.java
  - frameworks/runtime-src/proj.android/app/src/org/cocos2dx/lua/AppActivity.java (from cocos2d-x 3.17)

js
  - frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/AppActivity.java
  - frameworks/runtime-src/proj.android/app/src/org/cocos2dx/javascript/AppActivity.java ( from cocos2d-x 3.17)

Plugin < 2.4.0.3

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
# phunwareads
-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}
-dontwarn okio.**
-dontwarn okhttp3.**


# 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 com.google.protobuf.** { *; }
-dontwarn com.google.protobuf.**

-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 PhunwareAds v3.5.1+ 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'
}