Libgdx IOS robovm集成友盟(4.0.2版)

新版的友盟游戏统计已更改成.framework文件,本文主要讲述如何经过Libgdx的robovm集成IOS版本的友盟. 友盟游戏统计IOS下载地址: http://dev.umeng.com/game_analytics/game-ios/sdk-downloadjava

  1. 新建一个libs目录, 将UMMobClick.framework和CoreTelePhony.framework(依赖包)放入到libs目录下.

注意:CoreTelePhony.framework若是不放入会报错, Undefined symbols for architecture x86_64: "OBJC_CLASS$_CTTelephonyNetworkInfo", referenced from: objc-class-ref in UMMobClick(UMANUtil.o)ios

  1. robovm.xml文件下添加
<frameworkPaths>
    <path>libs</path>
  </frameworkPaths>

同时<frameworks></frameworks>下添加如下:app

<framework>CoreTelephony</framework>
 <framework>UMMobClick</framework>
  1. 接下来就是作代码绑定相关了,这里咱们只绑定了startWithConfigure方法以及计费统计的pay方法. 若是须要其余方法请自行绑定.
  • 绑定MobClick.h下的UMAnalyticsConfig 新建UMAnalyticsConfig.java.
@Library(Library.INTERNAL)
@NativeClass
public class UMAnalyticsConfig extends NSObject {

    @Property
    public native void setAppKey(String appKey);

    @Property
    public native String getAppKey();

    @Property
    public native String getSecret();

    @Property
    public native void setSecret(String secret);

    @Property
    public native String getChannelId();

    @Property
    public native void setChannelId(String channelId);

    @Property
    public native boolean getBCrashReportEnabled();

    @Property
    public native void setBCrashReportEnabled(boolean bCrashReportEnabled);

    @Property
    public native ReportPolicy getEPolicy();

    @Property
    public native void setEPolicy(ReportPolicy ePolicy);


    @Method(selector = "sharedInstance")
    public native static UMAnalyticsConfig sharedInstance();

}
  • 绑定枚举ReportPolicy 新建ReportPolicy.java
public enum ReportPolicy implements ValuedEnum {
    REALTIME(0),
    BATCH(1),
    SEND_INTERVAL(6)
    ;

    private final long n;
    private ReportPolicy(long n){
        this.n = n;
    }

    @Override
    public long value() {
        return n;
    }
}
  • 新建MobClick.java
@Library(Library.INTERNAL)
@NativeClass
public class MobClick extends NSObject implements UIAlertViewDelegate {
    @Override
    @Method(selector = "alertView:clickedButtonAtIndex:")
    public void clicked(UIAlertView alertView, @MachineSizedSInt long buttonIndex) {

    }

    @Override
    @Method(selector = "alertViewCancel:")
    public void cancel(UIAlertView alertView) {

    }

    @Override
    @Method(selector = "willPresentAlertView:")
    public void willPresent(UIAlertView alertView) {

    }

    @Override
    @Method(selector = "didPresentAlertView:")
    public void didPresent(UIAlertView alertView) {

    }

    @Override
    @Method(selector = "alertView:willDismissWithButtonIndex:")
    public void willDismiss(UIAlertView alertView, @MachineSizedSInt long buttonIndex) {

    }

    @Override
    @Method(selector = "alertView:didDismissWithButtonIndex:")
    public void didDismiss(UIAlertView alertView, @MachineSizedSInt long buttonIndex) {

    }

    @Override
    @Method(selector = "alertViewShouldEnableFirstOtherButton:")
    public boolean shouldEnableFirstOtherButton(UIAlertView alertView) {
        return false;
    }


    @Method(selector = "startWithConfigure:")
    public native static void startWithConfigure(UMAnalyticsConfig config);

    @Method(selector = "setLogEnabled:")
    public native static void setLogEnabled(boolean flag);
}
  • MobClickGameAnalytics.java
@Library(Library.INTERNAL)
@NativeClass
public class MobClickGameAnalytics extends NSObject {

    //+ (void)pay:(double)cash source:(int)source coin:(double)coin;
    @Method(selector = "pay:source:coin:")
    public static native void pay(double cash, int source, double coin);

    /** 玩家支付货币购买道具.
     @param cash 真实货币数量
     @param source 支付渠道
     @param item 道具名称
     @param amount 道具数量
     @param price 道具单价
     @return void
     */
//    + (void)pay:(double)cash source:(int)source item:(NSString *)item amount:(int)amount price:(double)price;
    @Method(selector = "pay:source:item:amount:price:")
    public static native void pay(double cash, int source, String item, int amout, double price);
}
  1. 接下来就能够在本身的工程里调用了
UMAnalyticsConfig umConfig = UMAnalyticsConfig.sharedInstance();
        umConfig.setAppKey("你的appKey");
        umConfig.setEPolicy(ReportPolicy.BATCH);
        umConfig.setChannelId("App Store");
        MobClick.startWithConfigure(umConfig);
相关文章
相关标签/搜索