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);
相關文章
相關標籤/搜索