cocos2dx之友盟统计(androidios)

cocos2dx之友盟统计(androidios),第1张

概述一、玩家登录,在lua代码中获取玩家的帐号信息 ---------账号登录统计--------------- if device.platform == "android" then local args = { 1, tostring(PlayerId),1 } local luaj = require "cocos.cocos2d.luaj" local sigs

一、玩家登录,在lua代码中获取玩家的帐号信息

---------账号登录统计--------------- if device.platform == "androID" then    local args = { 1,tostring(PlayerID),1 }    local luaj = require "cocos.cocos2d.luaj"    local sigs = "(ILjava/lang/String;I)I"    local classname = "com/cocos2dx/sample/LuaJavaBrIDge"    local ok,ret  = luaj.callStaticmethod(classname,"sendLuaToJavaProfileSignIn",args,sigs)    if not ok then        print("luaj error:",ret)    else        print("The ret is:",ret)    endelseif device.platform == "ios" then    iosProfileSignInWithPUID(tostring(PlayerID))    -- iosProfileSignInWithPUID("playerID_str_param")end---------账号登录统计--------------- 

lua中获取信息后,通过不同平台来调用不同平台的方法。
androID中,lua(–>c/c++)–>LuaJavaBrIDge–>java(androID)
ios中,lua(–>c/c++)–>oc(iOS)

androID情况:项目文件下,src–>com.cocos2dx.sample–>LuaJavaBrIDge.java

// 账号登录统计public static int sendLuaToJavaProfileSignIn(int type,String UserID,final int luaFuncID){    //System.out.printf("%n","sendLuaToJavaProfileSignIn **********************************");    //Log.d("tag","正sendLuaToJavaProfileSignIn播放中");    MobclickAgent.onProfileSignIn(UserID);   //友盟账号登录统计的方法    return 1;}

调用了友盟统计登录的方法即可。
还需要的一些代码编写以及配置情况:在src–>org.cocos2dx.lua–>AppActivity.java

@OverrIDeprotected voID onResume() {    super.onResume();     //添加友盟的部分    MobclickAgent.onResume(this);}@OverrIDepublic voID onPause(){    super.onPause();    //添加友盟的部分    MobclickAgent.onPause(this);}

在项目文件下,找到如下,在其中添加

<application>    <!-- umeng Sdk start -->    <Meta-data androID:value="584e516aa3251114e10012a3" androID:name="UMENG_APPKEY"/>    <Meta-data androID:value="umeng" androID:name="UMENG_CHANNEL"/>    <!-- umeng Sdk end --></application>

“584e516aa3251114e10012a3”:在友盟后台申请的应用Appkey(根据自己申请的来填写)。

<uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE"/><uses-permission androID:name="androID.permission.ACCESS_WIFI_STATE" /><uses-permission androID:name="androID.permission.INTERNET"/><uses-permission androID:name="androID.permission.READ_PHONE_STATE"/>

添加权限。

iOS情况:AppDelegate.h中,声明函数

//友盟统计登录static int iosProfileSignInWithPUID(lua_State *L);

AppDelegate.cpp中,applicationDIDFinishLaunching里面,lua注册函数

lua_register(L,"iosProfileSignInWithPUID",iosProfileSignInWithPUID);

以及实现函数

// lua 调用 c 友盟账号统计int AppDelegate::iosProfileSignInWithPUID(lua_State *L){    if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)    {        //从lua处得到账号信息,lua里面会调用已经注册的该函数iosProfileSignInWithPUID        std::string playerID = lua_tostring(L,1);        printf("玩家的playerID: %s\n",playerID.c_str());        //新建一个接口,这个接口能被c/c++函数iosProfileSignInWithPUID调用,接口中又可以调用oc代码,lua代码又可以调用该函数iosProfileSignInWithPUID        UMProfile::profileSignInWithPUID(playerID.c_str());    }    return 1;}

创建该接口
新建一个类UMProfile,有UMProfile.h文件和UMProfile.mm文件.h文件中声明函profileSignInWithPUID,
.mm文件实现函数,(.mm文件里面既可以写oc代码也可以写c/c++代码)

// 实现文件 UMProfile.cpp#include "UMProfile.h"//导入友盟sdk#import "UMMobClick/MobClick.h"//--------------------------------------------------voID UMProfile::profileSignInWithPUID(const char* userID){#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)    //获取用户账号后转换string类型    Nsstring *strNsstring = [[Nsstring alloc] initWithUTF8String:userID];    //调用友盟iOS统计函数即可。     [MobClick profileSignInWithPUID:strNsstring];#endif}
总结

以上是内存溢出为你收集整理的cocos2dx之友盟统计(android/ios)全部内容,希望文章能够帮你解决cocos2dx之友盟统计(android/ios)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1084717.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存