AgeCheq Integration Guide
For the Javascript version of cocos2d-x v3.x - (all other versions)
SDK Version
- ios: v3.02:03.25.2015
- android: v3.03 05.15.2015
Integration
Open a terminal and use the following command to install the SDKBOX AgeCheq plugin. Make sure you setup the SDKBOX installer correctly.
$ sdkbox import agecheq
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 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 AgeCheq configuration, you need to replace <app id>
and <zone id>
items with your specific AgeCheq ID account information.
"AgeCheq":{
"AppID":"ca0e20a3-3bb8-42e1-a5ac-55af7f63dbfc",
"DeveloperKey":"9102be76-232b-49b1-9c4f-1c6806d3a975"
}
Usage
Register Javascript Functions
You need to register all the AgeCheq JS functions with cocos2d-x before using them.
To do this:
* Modify ./frameworks/runtime-src/Classes/AppDelegate.cpp
to include the following headers:
#include "PluginAgeCheqJS.hpp"
#include "PluginAgeCheqJSHelper.h"
- Modify
./frameworks/runtime-src/Classes/AppDelegate.cpp
make sure to call:
sc->addRegisterCallback(register_all_PluginAgeCheqJS);
sc->addRegisterCallback(register_all_PluginAgeCheqJS_helper);
Initialize AgeCheq
Initialize the plugin by calling init()
where appropriate in your code. We
recommend to do this in the app.js
. Example:
sdkbox.PluginAgeCheq.init();
Using AgeCheq
After initialization you can begin to use the AgeCheq functionality. Use check
wherever you want from your code:
sdkbox.PluginAgeCheq.check("agecheqPin");
Catch AgeCheq events (optional)
This allows you to catch the AgeCheq
events so that you can perform operations based upon responses. A simple example might look like this:
sdkbox.PluginAgeCheq.init();
sdkbox.PluginAgeCheq.setListener({
checkResponse : function (rtn, rtnmsg, apiversion, checktype, appauthorized, appblocked, parentverified, under13, under18, underdevage, trials) {
cc.log("checkResponse rtn:" + rtn + " rtnmsg:" + rtnmsg
+ " apiversion:" + apiversion + " checktype:" + checktype
+ " appauthorized:" + appauthorized + " appblocked:" + appblocked
+ " parentverified:" + parentverified + " under13:" + under13
+ " under18:" + under18 + " underdevage:" + underdevage + " trials:" + trials);
},
associateDataResponse : function (rtn, rtnmsg) {
cc.log("associateDataResponse rtn:" + rtn + " rtnmsg:" + rtnmsg);
}
})
sdkbox.PluginAgeCheq.check("agecheqPin");
API Reference
Methods
sdkbox.PluginAgeCheq.init();
initialize the plugin instance.
sdkbox.PluginAgeCheq.setListener(listener);
Set listener to listen for adcolony events
sdkbox.PluginAgeCheq.check(ACPin);
The AgeCheq check method is used to determine the status of a child’s relationship with a particular online service. It requires the developer’s unique identifier, the child’s AgeCheq PIN as set up by their parent, and the unique identifier of the game or application.
@param ACPin This unique identifier is passed by the user to link them with the online service. This identifier may be letters, numbers, or symbols from 4-30 characters long.
sdkbox.PluginAgeCheq.associateData(ACPin, Data);
The associateData method allows you to save a string of information linking it to a particular AgeCheqPIN for a specific game or app. You’ll want to use that data later if a parent should unauthorize your online service.
@param ACPin This unique identifier is passed by the user to link them with the online service. This identifier may be letters, numbers, or symbols from 4-30 characters long. @param Data This field holds the data you want to store for later.
Listeners
checkResponse(rtn,
rtnmsg,
apiversion,
checktype,
appauthorized,
appblocked,
parentverified,
under13,
under18,
underdevage,
trials);
The delegate named checkResponse is triggered once the check command executes. It contains several status variables that you can check against.
@param rtn If the method made a good round-trip to the server and back, this value will be “OK”. If the method failed for some reason, this value will read “FAIL”. @param rtnmsg If the method failed for some reason, this value will hold a brief explanation of why it happened. If the method made a good round-trip to the server and back, this value will be empty. @param apiversion The version of the AgeCheq API used to fulfill requests. @param checktype The values will correspond to the following types: 0 = Normal check call 1 = Normal check as a result of a throttled call 2 = All data forced to “allow” as a result of a throttled call @param appauthorized If the game or app is authorized by an adult for use by a child under 13, the value will be true. If the game or app is not authorized by a parent, or if the device is not yet registered this value will be false. @param appblocked If the game or app is authorized by an adult for use by a child under 13, but the game is temporarily blocked by the authorizing parent the value will be true. If the game or app is authorized by a parent and they do not have the blocking switch on the value will be false. @param parentverified The values indicate the following statuses: 0 = Not verified 1 = Fully verified via payment or form 2 = Partially verified via EmailPlus, SMS, or VOIP 3 = All data forced to "allow" as the result of a trial call and the trials value will be incremented @param under13 This field will be true if the user identified by the AgeCheq PIN has a birthdate that makes them currently under the age of thirteen based on information provided to the AgeCheq Parent Dashboard. @param under18 This field will be true if the user identified by the AgeCheq PIN has a birthdate that makes them currently under the age of eighteen based on information provided to the AgeCheq Parent Dashboard. @param underdevage This field will be true if the user identified by the AgeCheq PIN has a birthdate that makes them currently under the age of set by the developer for the application in the Developer Dashboard. If this custom age is not set, this field will always be a false. @param trials If the application is set up in the AgeCheq Developer Dashboard (https://developer.agecheq.com) to use Application Trials, this field will return the number of times a check has been made but the app has not been authorized.
associateDataResponse(rtn, rtnmsg);
The delegate named associateDataResponse is triggered once the associateData command executes.
@param rtn If the method made a good round-trip to the server and back, this value will be “OK”. If the method failed for some reason, this value will read “FAIL”. @param rtnmsg If the method failed for some reason, this value will hold a brief explanation of why it happened. If the method made a good round-trip to the server and back, this value will be empty.
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 AgeCheq
bundle into your Xcode project, check Copy items if needed
when adding frameworks:
sdkbox.framework
PluginAgeCheq.framework
add the following system frameworks, if you don't already have them:
AdSupport.framework
Copy all source and header files from plugin/jsbindings/
to your projects Classes
folder.
NOTE: plugin/jsbindings/jsb2
for creator 1.7.
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.
proj.android
will be used as our<project_root>
for command-line and eclipse projectproj.android-studio
will be used as our<project_root>
for Android Studio project.
Copy Files
Copy the following jar files from plugin/android/libs
folder of this
bundle into your project's
AgeCheqLib.jar
PluginAgeCheq.jar
sdkbox.jar
-
If you're using cocos2d-x from source copy the jar files to:
Android command-line:
cocos2d/cocos/platform/android/java/libs
Android Studio:
cocos2d/cocos/platform/android/java/libs cocos2d/cocos/platform/android/libcocos2dx/libs
-
If you're using cocos2d-js or lua copy the jar files to:
Android command-line:
frameworks/cocos2d-x/cocos/platform/android/java/libs
Android Studio:
frameworks/cocos2d-x/cocos/platform/android/java/libs frameworks/cocos2d-x/cocos/platform/android/libcocos2dx/libs
-
If you're using prebuilt cocos2d-x copy the jar files to:
Android command-line:
proj.android/libs
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"/>
Edit Android.mk
Edit <project_root>/jni/Android.mk
to:
Add additional requirements to LOCAL_WHOLE_STATIC_LIBRARIES:
LOCAL_WHOLE_STATIC_LIBRARIES += PluginAgeCheq
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, ./pluginagecheq)
This means that your ordering should look similar to this:
$(call import-add-path,$(LOCAL_PATH))
$(call import-module, ./sdkbox)
$(call import-module, ./pluginagecheq)
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/jsbindings/
to your projects Classes
folder.
NOTE: plugin/jsbindings/jsb2
for creator 1.7.
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
- Find the AppActivity.java
find . -name "AppActivity.java"
- Replace
extends Cocos2dxActivity
withextends 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
-
If you're using cocos2d-x from source, assuming you are in the proj.android directory, Cocos2dxActivity.java is located:
../../cocos2d-x/cocos/platform/android/java/src/org/cocos2dx/ lib/Cocos2dxActivity.java
-
If you're using the prebuilt cocos2d-x libraries assuming you are in the
proj.android
directory, Cocos2dxActivity.java is located:./src/org/cocos2dx/lib/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
- Modify Cocos2dxActivity.java to add the following imports:
import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
- Second, modify Cocos2dxActivity.java to edit the
onCreate(final Bundle savedInstanceState)
function to add a call toSDKBox.init(this);
. The placement of this call is important. It must be done after the call toonLoadNativeLibraries();
. Example:
onLoadNativeLibraries();
SDKBox.init(this);
-
Last, we need to insert the proper overrides code. There are a few rules here.
-
If the method listed has not been defined, add it.
-
If the method listed has been defined, add the calls to
SDKBox
in the same existing function.
-
@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)
- Edit
project.properties
to specify aProguard
configuration file. Example:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
- Edit the file you specified to include the following:
# 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 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.