帮助与文档

> >

一、下载并导入MobLink

下载Cocos2dx-For-MobLink,下载完成后打开项目,将/Classes/C2DXMobLink文件夹复制到您的cocos2dx项目/Classes目录下

二、快速接入

1. Android端接入

i. 复制/proj.android-studio/app/libs目录下的MobCommons.jar、MobLink-1.1.0.jar、MobLink-Cocos2dx.jar、MobTools.jar到您的coco2dx项目libs目录下

ii. 添加编译需要的cpp源代码(Android.mk)

../../../Classes/C2DXMobLink/C2DXMobLink.cpp \
../../../Classes/C2DXMobLink/C2DXMobLinkScene.cpp \
../../../Classes/C2DXMobLink/C2DXMobLinkCallBack.cpp \
../../../Classes/C2DXMobLink/Android/C2DXAndroidMobLink.cpp \
../../../Classes/C2DXMobLink/Android/C2DXAndroidActionListener.cpp \
../../../Classes/C2DXMobLink/Android/com_mob_moblink_cocos2dx_ActionListener.cpp \
../../../Classes/C2DXMobLink/Android/C2DXAndroidRestoreSceneListener.cpp \
../../../Classes/C2DXMobLink/Android/com_mob_moblink_cocos2dx_RestoreSceneListener.cpp \
../../../Classes/C2DXMobLink/Android/JSON/CCJSONConverter.cpp \
../../../Classes/C2DXMobLink/Android/JSON/cJSON/cJSON.c

iii. 添加编译需要的头文件路径(Android.mk)

$(LOCAL_PATH)/../../../Classes/C2DXMobLink \
$(LOCAL_PATH)/../../../Classes/C2DXMobLink/Android \
$(LOCAL_PATH)/../../../Classes/C2DXMobLink/Android/JSON \
$(LOCAL_PATH)/../../../Classes/C2DXMobLink/Android/JSON/cJSON

iv. 配置AndroidManiFest.xml文件

请参考原生Android平台的配置文件中的, 配置AndroidManiFest.xml 文件部分

2. iOS端接入

2.1. 对于iOS,还需要对Xcode项目进行一些配置 1.(重要) 配置 MobAppKey 以及 MobAppSecret 在Xcode项目对应的info.plist文件中设置应MobLink官网获得的AppKey和AppSecret

2.2. 添加MobLink库 在本demo项目的proj.ios_mac文件夹中找到SDK文件夹,将其添加到您的Xcode项目中(内含两个framework)

2.3. 添加系统依赖库

择项目Target-Build Phases-Link Binary With Libraries,然后选择“+”进行添加系统库:

libsqlite3, libz1.2.5, libstdc++, libicucore

2.4. 配置Universal Link 以及 URL Scheme

i. URL Scheme 项目中需要配置URL Scheme以用于场景恢复时跳转到应用中(这里的scheme要唯一确定,不要与其他应用一致,建议使用项目名称作为scheme)。请参考下图配置您自己的URL Scheme:

ii.Universal Link 然后在项目中配置Universal Link,请务必填写后台生成的Universal Link地址 (建议直接从管理后台拷贝)参考下图:

上述步骤其实与原生iOS集成MobLink一致,具体可参考iOS快速集成中的第三点的第1、2小点。

三、 添加代码

1.设置场景回调

i.自行构建回调,自行处理得到的场景参数scene

void sceneHandler(C2DXMobLinkScene *scene)
{
    //自行处理取得的scene
    log("path = %s", scene->path.c_str());
    log("source = %s", scene->source.c_str());
    __Dictionary *custom = scene->getCustomParams();

    std::string content;
    content += "path:"; content += scene->path.c_str(); content += "\n";
    content += "source:"; content += scene->source.c_str(); content += "\n";
    content += "params:\n";

    DictElement *element;
    CCDICT_FOREACH(custom, element)
        {
            const char *key = element -> getStrKey();
            __String *obj = (__String*)element -> getObject();
            log("key = %s, value = %s",key,obj -> getCString());
            content += key; content += ":"; content += obj->getCString(); content += "\n";
        }

    MessageBox(content.c_str(), "得到场景恢复回调");
}

ii.将回调传入

//设置场景恢复之回调
C2DXMobLink::setSceneRestoreCallBack(sceneHandler);

2.获取Mobid

i.自行构建回调,自行处理得到的mobid

void getMobIdHandler(const char * mobid)
{
    log("result - mobid = %s", mobid);
    std::string content = "mobId:";
    content += mobid;
    MessageBox(content.c_str(), "获取MobId的回调");
}

ii.构建场景参数,并传入上述回调

C2DXMobLinkScene *scene = new C2DXMobLinkScene();
scene->path = "the path";
scene->source = "the source";

__Dictionary *customParams = __Dictionary::create();
customParams->setObject(__String::create("999"), "Price");
customParams->setObject(__String::create("1"), "Chapter");
customParams->setObject(__String::create("Dragon Fire"), "ChapterName");
scene->setCustomParams(customParams);

C2DXMobLink::getMobId(scene, getMobIdHandler);

注意:获取到MobId后,应通过分享的方式将带有Mobid的链接分享出去 对于分享,我们更建议使用Cocos2dx For ShareSDK

相关文档