新版的友盟遊戲統計已更改成.framework文件,本文主要講述如何經過Libgdx的robovm集成IOS版本的友盟. 友盟遊戲統計IOS下載地址: http://dev.umeng.com/game_analytics/game-ios/sdk-downloadjava
注意:CoreTelePhony.framework若是不放入會報錯, Undefined symbols for architecture x86_64: "OBJC_CLASS$_CTTelephonyNetworkInfo", referenced from: objc-class-ref in UMMobClick(UMANUtil.o)ios
<frameworkPaths> <path>libs</path> </frameworkPaths>
同時<frameworks></frameworks>下添加如下:app
<framework>CoreTelephony</framework> <framework>UMMobClick</framework>
@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(); }
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; } }
@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); }
@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); }
UMAnalyticsConfig umConfig = UMAnalyticsConfig.sharedInstance(); umConfig.setAppKey("你的appKey"); umConfig.setEPolicy(ReportPolicy.BATCH); umConfig.setChannelId("App Store"); MobClick.startWithConfigure(umConfig);