diff --git a/umenganalysics/IOSLauncher.java b/umenganalysics/IOSLauncher.java new file mode 100644 index 0000000..33e0486 --- /dev/null +++ b/umenganalysics/IOSLauncher.java @@ -0,0 +1,66 @@ +package net.mwply.bangdings; + +import java.util.ArrayList; +import java.util.List; + +import org.robovm.apple.foundation.NSArray; +import org.robovm.apple.foundation.NSAutoreleasePool; +import org.robovm.apple.foundation.NSDictionary; +import org.robovm.apple.foundation.NSString; +import org.robovm.apple.uikit.UIApplication; +import org.robovm.apple.uikit.UIApplicationLaunchOptions; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.backends.iosrobovm.IOSApplication; +import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; + +import net.mwplay.umenganalysics.MobClick; +import net.mwplay.umenganalysics.MobClickGameAnalytics; +import net.mwplay.umenganalysics.MobClickSocialAnalytics; +import net.mwplay.umenganalysics.MobClickSocialWeibo; +import net.mwplay.umenganalysics.ReportPolicy; +import net.mwply.bangdings.GdxGame; + +public class IOSLauncher extends IOSApplication.Delegate { + @Override + protected IOSApplication createApplication() { + IOSApplicationConfiguration config = new IOSApplicationConfiguration(); + return new IOSApplication(new GdxGame(), config); + } + + public static void main(String[] argv) { + NSAutoreleasePool pool = new NSAutoreleasePool(); + UIApplication.main(argv, null, IOSLauncher.class); + pool.close(); + } + + @Override + public boolean didFinishLaunching(UIApplication application, + UIApplicationLaunchOptions launchOptions) { + + MobClick.startWithAppkey("549fbc52fd98c5ca3600092b", + ReportPolicy.BATCH, "ios"); + + MobClickGameAnalytics.pay(100, 1, 200); + MobClickGameAnalytics.buy("xxoo", 1, 100); + MobClickGameAnalytics.use("xxoo", 1, 100); + + MobClickGameAnalytics.startLevel("1"); + MobClickGameAnalytics.finishLevel("1"); + MobClickGameAnalytics.failLevel("1"); + + final NSDictionary dic = new NSDictionary(); + dic.setAssociatedObject(new NSString("1"), new NSString("1")); + dic.setAssociatedObject(new NSString("2"), new NSString("2")); + + MobClickSocialWeibo weibo = new MobClickSocialWeibo(MobClickSocialWeibo.MobClickSocialTypeSina(), + "xxxxxxxooooo", "12345", dic); + List weibos = new ArrayList(); + weibos.add(weibo); + + MobClickSocialAnalytics.postWeiboCounts(weibos, + "549fbc52fd98c5ca3600092b", "测试", null); + + return super.didFinishLaunching(application, launchOptions); + } +} \ No newline at end of file diff --git a/umenganalysics/MobClick.java b/umenganalysics/MobClick.java new file mode 100644 index 0000000..86c6624 --- /dev/null +++ b/umenganalysics/MobClick.java @@ -0,0 +1,472 @@ +package net.mwplay.umenganalysics; + +import org.robovm.apple.corelocation.CLLocation; +import org.robovm.apple.foundation.NSDictionary; +import org.robovm.apple.foundation.NSNotification; +import org.robovm.apple.foundation.NSObject; +import org.robovm.apple.uikit.UIAlertView; +import org.robovm.apple.uikit.UIAlertViewDelegate; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.rt.bro.annotation.MachineSizedSInt; + + +// +//MobClick.h +//Analytics +// +//Copyright (C) 2010-2014 Umeng.com . All rights reserved. + +//#import +//#import +// +//#define UMOnlineConfigDidFinishedNotification @"OnlineConfigDidFinishedNotification" +//#define XcodeAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] +// +///** +//REALTIME只在模拟器和DEBUG模式下生效,真机的release模式会自动改成BATCH。 +//*/ +//typedef enum { +//REALTIME = 0, //实时发送 (只在测试模式下有效) +//BATCH = 1, //启动发送 +//SEND_INTERVAL = 6, //最小间隔发送 ([90-86400]s, default 90s) +// +//// deprecated strategy: +//SENDDAILY = 4, //每日发送 (not available) +//SENDWIFIONLY = 5, //仅在WIFI下时启动发送 (not available) +//SEND_ON_EXIT = 7 //进入后台时发送 (not avilable, will be support later) +//} ReportPolicy; +// +//@class CLLocation; + + +//@interface MobClick : NSObject + +//#pragma mark basics + +///--------------------------------------------------------------------------------------- +/// @name 设置 +///--------------------------------------------------------------------------------------- +@NativeClass +public class MobClick extends NSObject implements UIAlertViewDelegate{ + + @Override + @Method(selector = "alertView:clickedButtonAtIndex:") + public void clicked(UIAlertView alertView, + @MachineSizedSInt long buttonIndex) { + // TODO Auto-generated method stub + + } + + @Override + @Method(selector = "alertViewCancel:") + public + void cancel(UIAlertView alertView) { + // TODO Auto-generated method stub + + } + + @Override + @Method(selector = "willPresentAlertView:") + public + void willPresent(UIAlertView alertView) { + // TODO Auto-generated method stub + + } + + @Override + @Method(selector = "didPresentAlertView:") + public + void didPresent(UIAlertView alertView) { + // TODO Auto-generated method stub + + } + + @Override + @Method(selector = "alertView:willDismissWithButtonIndex:") + public + void willDismiss(UIAlertView alertView, @MachineSizedSInt long buttonIndex) { + // TODO Auto-generated method stub + + } + + @Override + @Method(selector = "alertView:didDismissWithButtonIndex:") + public + void didDismiss(UIAlertView alertView, @MachineSizedSInt long buttonIndex) { + // TODO Auto-generated method stub + + } + + @Override + @Method(selector = "alertViewShouldEnableFirstOtherButton:") + public + boolean shouldEnableFirstOtherButton(UIAlertView alertView) { + // TODO Auto-generated method stub + return false; + } +/** 设置app版本号。由于历史原因需要和xcode3工程兼容,友盟提取的是Build号(CFBundleVersion), +如果需要和App Store上的版本一致,请调用此方法。 +@param appVersion 版本号,例如设置成`XcodeAppVersion`. +@return void. +*/ +//+ (void)setAppVersion:(NSString *)appVersion; +@Method(selector = "setAppVersion:") +public native static void setAppVersion(String appVersion); + +/** 开启CrashReport收集, 默认YES(开启状态). +@param value 设置为NO,可关闭友盟CrashReport收集功能. +@return void. +*/ +//+ (void)setCrashReportEnabled:(BOOL)value; +@Method(selector = "setCrashReportEnabled:") +public native static void setCrashReportEnabled(boolean value); + +/** 设置是否打印sdk的log信息, 默认NO(不打印log). +@param value 设置为YES,umeng SDK 会输出log信息可供调试参考. 除非特殊需要,否则发布产品时需改回NO. +@return void. +*/ +//+ (void)setLogEnabled:(BOOL)value; +@Method(selector = "setLogEnabled:") +public native static void setLogEnabled(boolean value); + +/** 设置是否开启background模式, 默认YES. +@param value 为YES,SDK会确保在app进入后台的短暂时间保存日志信息的完整性,对于已支持background模式和一般app不会有影响. + 如果该模式影响某些App在切换到后台的功能,也可将该值设置为NO. +@return void. +*/ +//+ (void)setBackgroundTaskEnabled:(BOOL)value; +@Method(selector = "setBackgroundTaskEnabled:") +public native static void setBackgroundTaskEnabled(boolean value); + +/** 设置是否对日志信息进行加密, 默认NO(不加密). +@param value 设置为YES, umeng SDK 会将日志信息做加密处理 +@return void. +*/ +//+ (void)setEncryptEnabled:(BOOL)value; +@Method(selector = "setEncryptEnabled:") +public native static void setEncryptEnabled(boolean value); +///--------------------------------------------------------------------------------------- +/// @name 开启统计 +///--------------------------------------------------------------------------------------- + +/** 初始化友盟统计模块 +@param appKey 友盟appKey. +@return void +*/ +//+ (void)startWithAppkey:(NSString *)appKey; +@Method(selector = "startWithAppkey:") +public native static void startWithAppkey(String appKey); + +/** 初始化友盟统计模块 +@param appKey 友盟appKey. +@param reportPolicy 发送策略, 默认值为:BATCH,即“启动发送”模式 +@param channelId 渠道名称,为nil或@""时, 默认为@"App Store"渠道 +@return void +*/ +//+ (void)startWithAppkey:(NSString *)appKey reportPolicy:(ReportPolicy)rp channelId:(NSString *)cid; +@Method(selector = "startWithAppkey:reportPolicy:channelId:") +public native static void startWithAppkey(String appKey, ReportPolicy rp, String cid); + +/** 当reportPolicy == SEND_INTERVAL 时设定log发送间隔 +@param second 单位为秒,最小90秒,最大86400秒(24hour). +@return void. +*/ +//+ (void)setLogSendInterval:(double)second; +@Method(selector = "setLogSendInterval:") +public native static void setLogSendInterval(double second); + +/** 设置日志延迟发送 +@param second 设置一个[0, second]范围的延迟发送秒数,最大值1800s. +@return void +*/ +//+ (void)setLatency:(int)second; +@Method(selector = "setLatency:") +public native static void setLatency(int second); + +///--------------------------------------------------------------------------------------- +/// @name 页面计时 +///--------------------------------------------------------------------------------------- + +/** 手动页面时长统计, 记录某个页面展示的时长. +@param pageName 统计的页面名称. +@param seconds 单位为秒,int型. +@return void. +*/ +//+ (void)logPageView:(NSString *)pageName seconds:(int)seconds; +@Method(selector = "logPageView:seconds:") +public native static void logPageView(int second); + +/** 自动页面时长统计, 开始记录某个页面展示时长. +使用方法:必须配对调用beginLogPageView:和endLogPageView:两个函数来完成自动统计,若只调用某一个函数不会生成有效数据。 +在该页面展示时调用beginLogPageView:,当退出该页面时调用endLogPageView: +@param pageName 统计的页面名称. +@return void. +*/ +//+ (void)beginLogPageView:(NSString *)pageName; +@Method(selector = "beginLogPageView:") +public native static void beginLogPageView(String pageName); + +/** 自动页面时长统计, 结束记录某个页面展示时长. +使用方法:必须配对调用beginLogPageView:和endLogPageView:两个函数来完成自动统计,若只调用某一个函数不会生成有效数据。 +在该页面展示时调用beginLogPageView:,当退出该页面时调用endLogPageView: +@param pageName 统计的页面名称. +@return void. +*/ +//+ (void)endLogPageView:(NSString *)pageName; +@Method(selector = "endLogPageView:") +public native static void endLogPageView(String pageName); + +//#pragma mark event logs + +///--------------------------------------------------------------------------------------- +/// @name 事件统计 +///--------------------------------------------------------------------------------------- + +/** 自定义事件,数量统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID + +@param eventId 网站上注册的事件Id. +@param label 分类标签。不同的标签会分别进行统计,方便同一事件的不同标签的对比,为nil或空字符串时后台会生成和eventId同名的标签. +@param accumulation 累加值。为减少网络交互,可以自行对某一事件ID的某一分类标签进行累加,再传入次数作为参数。 +@return void. +*/ +//+ (void)event:(NSString *)eventId; //等同于 event:eventId label:eventId; +@Method(selector = "event:") +public native static void event(String eventId); + +/** 自定义事件,数量统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID +*/ +//+ (void)event:(NSString *)eventId label:(NSString *)label; // label为nil或@""时,等同于 event:eventId label:eventId; +@Method(selector = "event:label:") +public native static void event(String eventId, String label); + +/** 自定义事件,数量统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID +*/ +//+ (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes; +@Method(selector = "event:attributes:") +public native static void event(String eventId, NSDictionary NSDictionary); + +//+ (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes counter:(int)number; +@Method(selector = "event:attributes:counter:") +public native static void event(String eventId, NSDictionary attributes, int number); + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +beginEvent,endEvent要配对使用,也可以自己计时后通过durations参数传递进来 + +@param eventId 网站上注册的事件Id. +@param label 分类标签。不同的标签会分别进行统计,方便同一事件的不同标签的对比,为nil或空字符串时后台会生成和eventId同名的标签. +@param primarykey 这个参数用于和event_id一起标示一个唯一事件,并不会被统计;对于同一个事件在beginEvent和endEvent 中要传递相同的eventId 和 primarykey +@param millisecond 自己计时需要的话需要传毫秒进来 +@return void. + + +@warning 每个event的attributes不能超过10个 +eventId、attributes中key和value都不能使用空格和特殊字符,且长度不能超过255个字符(否则将截取前255个字符) +id, ts, du是保留字段,不能作为eventId及key的名称 + +*/ +//+ (void)beginEvent:(NSString *)eventId; +@Method(selector = "beginEvent:") +public native static void beginEvent(String eventId); + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ +//+ (void)endEvent:(NSString *)eventId; +@Method(selector = "endEvent:") +public native static void endEvent(String eventId); + + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ + +//+ (void)beginEvent:(NSString *)eventId label:(NSString *)label; +@Method(selector = "beginEvent:label:") +public native static void beginEvent(String eventId, String label); + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ + +//+ (void)endEvent:(NSString *)eventId label:(NSString *)label; +@Method(selector = "endEvent:label:") +public native static void endEvent(String eventId, String label); + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ + +//+ (void)beginEvent:(NSString *)eventId primarykey :(NSString *)keyName attributes:(NSDictionary *)attributes; +@Method(selector = "beginEvent:primarykey:attributes:") +public native static void beginEvent(String eventId, String keyName, NSDictionary attributes); + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ + +//+ (void)endEvent:(NSString *)eventId primarykey:(NSString *)keyName; +@Method(selector = "endEvent:primarykey:") +public native static void endEvent2(String eventId, String keyName); + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ + +//+ (void)event:(NSString *)eventId durations:(int)millisecond; +@Method(selector = "event:durations:") +public native static void event(String eventId, int millisecond); + + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ + +//+ (void)event:(NSString *)eventId label:(NSString *)label durations:(int)millisecond; +@Method(selector = "event:label:durations:") +public native static void event(String eventId, String label, int millisecond); + +/** 自定义事件,时长统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID. +*/ +//+ (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes durations:(int)millisecond; +@Method(selector = "event:attributes:durations:") +public native static void event2(String eventId, NSDictionary attributes, int millisecond); + +//#pragma mark AutoUpdate and Online Configure +///--------------------------------------------------------------------------------------- +/// @name 按渠道自动更新 +///--------------------------------------------------------------------------------------- + +/** 按渠道检测更新 +检查当前app是否有更新,有则弹出UIAlertView提示用户,当用户点击升级按钮时app会跳转到您预先设置的网址。 +无更新不做任何操作。 +需要先在服务器端设置app版本信息,默认渠道是App Store. +@return void. +*/ +//+ (void)checkUpdate; +@Method(selector = "checkUpdate") +public native static void checkUpdate(); + +/** 按渠道检测更新 +检查当前app是否有更新,有则弹出UIAlertView提示用户,当用户点击升级按钮时app会跳转到您预先设置的网址。 +无更新不做任何操作。 +需要先在服务器端设置app版本信息,默认渠道是App Store. + +@param title 对应UIAlertView的title. +@param cancelTitle 对应UIAlertView的cancelTitle. +@param otherTitle 对应UIAlertView的otherTitle. +@return void. +*/ +//+ (void)checkUpdate:(NSString *)title cancelButtonTitle:(NSString *)cancelTitle otherButtonTitles:(NSString *)otherTitle; +@Method(selector = "checkUpdate:cancelButtonTitle:otherButtonTitles:") +public native static void checkUpdate(String title, String cancelTitle, String otherTitle); + +/** 设置自由控制更新callback函数 +若程序需要自由控制收到更新内容后的流程可设置delegate和callback函数来完成 + +@param delegate 需要自定义checkUpdate的对象. +@param callBackSelectorWithDictionary 当checkUpdate事件完成时此方法会被调用,同时标记app更新信息的字典被传回. +*/ +//+ (void)checkUpdateWithDelegate:(id)delegate selector:(SEL)callBackSelectorWithDictionary; +//@Method(selector = "checkUpdateWithDelegate:selector:") +//public native static void checkUpdateWithDelegate(Object delegate, SEL callBackSelectorWithDictionary); + +///--------------------------------------------------------------------------------------- +/// @name 在线参数:可以动态设定应用中的参数值 +///--------------------------------------------------------------------------------------- + +/** 此方法会检查并下载服务端设置的在线参数,例如可在线更改SDK端发送策略。 +请在[MobClick startWithAppkey:]方法之后调用; +监听在线参数更新是否完成,可注册UMOnlineConfigDidFinishedNotification通知 +@param . +@return void. +*/ +//+ (void)updateOnlineConfig; +@Method(selector = "updateOnlineConfig") +public native static void updateOnlineConfig(); + +/** 返回已缓存的在线参数值 +带参数的方法获取某个key的值,不带参数的获取所有的在线参数. +需要先调用updateOnlineConfig才能使用,如果想知道在线参数是否完成完成,请监听UMOnlineConfigDidFinishedNotification +@param key +@return (NSString *) . +*/ +//+ (NSString *)getConfigParams:(NSString *)key; +//+ (NSDictionary *)getConfigParams; +//+ (NSString *)getAdURL; +@Method(selector = "getConfigParams:") +public native static String getConfigParams(String key); +@Method(selector = "getConfigParams") +public native static NSDictionary getConfigParams(); +@Method(selector = "getAdURL") +public native static String getAdURL(); + +///--------------------------------------------------------------------------------------- +/// @name 地理位置设置 +/// 需要链接 CoreLocation.framework 并且 #import +///--------------------------------------------------------------------------------------- + +/** 设置经纬度信息 +@param latitude 纬度. +@param longitude 经度. +@return void +*/ +//+ (void)setLatitude:(double)latitude longitude:(double)longitude; +@Method(selector = "setLatitude:longitude:") +public native static void setLatitude(double latitude, double longitude); + +/** 设置经纬度信息 +@param location CLLocation 经纬度信息 +@return void +*/ +//+ (void)setLocation:(CLLocation *)location; +@Method(selector = "setLocation:") +public native static void setLatitude(CLLocation location); + +///--------------------------------------------------------------------------------------- +/// @name Utility函数 +///--------------------------------------------------------------------------------------- + +/** 判断设备是否越狱,依据是否存在apt和Cydia.app +*/ +//+ (BOOL)isJailbroken; +@Method(selector = "isJailbroken") +public native static boolean isJailbroken(); + +/** 判断App是否被破解 +*/ +//+ (BOOL)isPirated; +@Method(selector = "isPirated") +public native static boolean isPirated(); + +//#pragma mark DEPRECATED + +//+ (void)event:(NSString *)eventId acc:(NSInteger)accumulation; +@Method(selector = "event:acc:") +public native static void eventWithAccumulation(String eventId, int accumulation); + +/** 自定义事件,数量统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID +*/ +//+ (void)event:(NSString *)eventId label:(NSString *)label acc:(NSInteger)accumulation; +@Method(selector = "event:label:acc:") +public native static void eventWithAccumulation(String eventId, String label, int accumulation); +/** 自定义事件,数量统计. +使用前,请先到友盟App管理后台的设置->编辑自定义事件 中添加相应的事件ID,然后在工程中传入相应的事件ID +*/ + +/** 友盟模块启动 +[MobClick startWithAppkey:]通常在application:didFinishLaunchingWithOptions:里被调用监听App启动和退出事件, +如果开发者无法在此处添加友盟的[MobClick startWithAppkey:]方法,App的启动事件可能会无法监听,此时需要手动调用[MobClick startSession:nil]来启动友盟的session。 +上述情况通常发生在某些第三方框架生成的app里,普通app不用关注该API. +*/ +//+ (void)startSession:(NSNotification *)notification; +@Method(selector = "startSession:") +public native static void startSession(NSNotification startSession); + +} diff --git a/umenganalysics/MobClickGameAnalytics.java b/umenganalysics/MobClickGameAnalytics.java new file mode 100644 index 0000000..fae5c4f --- /dev/null +++ b/umenganalysics/MobClickGameAnalytics.java @@ -0,0 +1,219 @@ +package net.mwplay.umenganalysics; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; + + +// +//MobClickGameAnalytics.h +//Analytics +// +//Copyright (C) 2010-2014 Umeng.com . All rights reserved. +@NativeClass +public class MobClickGameAnalytics extends NSObject{ +//@interface MobClickGameAnalytics : NSObject + +//#pragma mark - +//#pragma mark user methods + +/** active user sign-in. + +使用sign-In函数后,如果结束该PUID的统计,需要调用sign-Off函数 +@param puid : user's ID +@param provider : 不能以下划线"_"开头,使用大写字母和数字标识; 如果是上市公司,建议使用股票代码。 +@return void. +*/ +//+ (void)profileSignInWithPUID:(NSString *)puid; +//+ (void)profileSignInWithPUID:(NSString *)puid provider:(NSString *)provider; +@Method(selector = "profileSignInWithPUID:") +public native static void profileSignInWithPUID(String puid); + +@Method(selector = "profileSignInWithPUID:provider:") +public native static void profileSignInWithPUID(String puid, String provider); + +/** active user sign-off. +停止sign-in PUID的统计 +@return void. +*/ +//+ (void)profileSignOff; +@Method(selector = "profileSignOff") +public native static void profileSignOff(); + +//#pragma mark - +//#pragma mark GameLevel methods +///--------------------------------------------------------------------------------------- +/// @name set game level +///--------------------------------------------------------------------------------------- + +/** 设置玩家的等级. +*/ + +/** 设置玩家等级属性. +@param level 玩家等级 +@return void +*/ +//+ (void)setUserLevelId:(int)level; +@Method(selector = "setUserLevelId:") +public native static void setUserLevelId(int level); + +///--------------------------------------------------------------------------------------- +/// @name 关卡统计 +///--------------------------------------------------------------------------------------- + +/** 记录玩家进入关卡,通过关卡及失败的情况. +*/ + + +/** 进入关卡. +@param level 关卡 +@return void +*/ +//+ (void)startLevel:(NSString *)level; +@Method(selector = "startLevel:") +public native static void startLevel(String level); + +/** 通过关卡. +@param level 关卡,如果level == nil 则为当前关卡 +@return void +*/ +//+ (void)finishLevel:(NSString *)level; +@Method(selector = "finishLevel:") +public native static void finishLevel(String level); + +/** 未通过关卡. +@param level 关卡,如果level == nil 则为当前关卡 +@return void +*/ + +//+ (void)failLevel:(NSString *)level; +@Method(selector = "failLevel:") +public native static void failLevel(String level); + + +//#pragma mark - +//#pragma mark Pay methods + +///--------------------------------------------------------------------------------------- +/// @name 支付统计 +///--------------------------------------------------------------------------------------- + +/** 记录玩家使用真实货币的消费情况 +*/ + + +/** 玩家支付货币兑换虚拟币. +@param cash 真实货币数量 +@param source 支付渠道 +@param coin 虚拟币数量 +@return void +*/ + +//+ (void)pay:(double)cash source:(int)source coin:(double)coin; +@Method(selector = "pay:source:coin:") +public native static 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 native static void pay(double cash, int source, String item, int amount, double price); + +//#pragma mark - +//#pragma mark Buy methods + +///--------------------------------------------------------------------------------------- +/// @name 虚拟币购买统计 +///--------------------------------------------------------------------------------------- + +/** 记录玩家使用虚拟币的消费情况 +*/ + + +/** 玩家使用虚拟币购买道具 +@param item 道具名称 +@param amount 道具数量 +@param price 道具单价 +@return void +*/ +//+ (void)buy:(NSString *)item amount:(int)amount price:(double)price; +@Method(selector = "buy:amount:price:") +public native static void buy(String item, int amount, double price); + +//#pragma mark - +//#pragma mark Use methods + + +///--------------------------------------------------------------------------------------- +/// @name 道具消耗统计 +///--------------------------------------------------------------------------------------- + +/** 记录玩家道具消费情况 +*/ + + +/** 玩家使用虚拟币购买道具 +@param item 道具名称 +@param amount 道具数量 +@param price 道具单价 +@return void +*/ + +//+ (void)use:(NSString *)item amount:(int)amount price:(double)price; +@Method(selector = "use:amount:price:") +public native static void use(String item, int amount, double price); + +//#pragma mark - +//#pragma mark Bonus methods + + +///--------------------------------------------------------------------------------------- +/// @name 虚拟币及道具奖励统计 +///--------------------------------------------------------------------------------------- + +/** 记录玩家获赠虚拟币及道具的情况 +*/ + + +/** 玩家获虚拟币奖励 +@param coin 虚拟币数量 +@param source 奖励方式 +@return void +*/ + +//+ (void)bonus:(double)coin source:(int)source; +@Method(selector = "bonus:source:") +public native static void bonus(double coin, int source); + +/** 玩家获道具奖励 +@param item 道具名称 +@param amount 道具数量 +@param price 道具单价 +@param source 奖励方式 +@return void +*/ + +//+ (void)bonus:(NSString *)item amount:(int)amount price:(double)price source:(int)source; +@Method(selector = "bonus:amount:price:source:") +public native static void bonus(String item, int amount, double price, int source); + +//#pragma mark DEPRECATED +//已经被新的setUserLevelId:方法替代,请使用新的API。 +//+ (void)setUserLevel:(NSString *)level; +@Method(selector = "setUserLevel:") +public native static void setUserLevel(String level); + + +//已经被新的active user方法替代,请使用新的API。 +//+ (void)setUserID:(NSString *)userId sex:(int)sex age:(int)age platform:(NSString *)platform; +@Method(selector = "setUserID:sex:age:platform:") +public native static void setUserID(String userId, int sex, int age, String platform); + +//@end +} diff --git a/umenganalysics/MobClickSocialAnalytics.java b/umenganalysics/MobClickSocialAnalytics.java new file mode 100644 index 0000000..269e430 --- /dev/null +++ b/umenganalysics/MobClickSocialAnalytics.java @@ -0,0 +1,52 @@ +package net.mwplay.umenganalysics; + +import java.util.List; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.annotation.Block; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; + + +@NativeClass +public class MobClickSocialAnalytics extends NSObject{ + + /** + 发送统计完成的block对象 + */ + //typedef void (^MobClickSocialAnalyticsCompletion)(NSDictionary * response, NSError *error); + + + /** + 负责统计微博类。 + 分享微博完成之后需要先构造`MobClickSocialWeibo`组成微博数组,然后再用类方法发送微博数组 + + ``` + +(void)postWeiboCounts:(NSArray *)weibos appKey:(NSString *)appKey topic:(NSString *)topic completion:(MobClickSocialAnalyticsCompletion)completion; + ``` + + 例如 + + + MobClickSocialWeibo *tencentWeibo = [[MobClickSocialWeibo alloc] initWithPlatformType:UMSocialTypeTencent weiboId:nil userId:@"tencent123" param:@{@"gender":@"1"}]; + [MobClickSocialAnalytics postWeibos:@[tencentWeibo] appKey:@"507fcab25270157b37000010" topic:@"test" completion:^(NSDictionary *result, NSError *error) { + NSLog(@"result is %@", result); + }]; + + */ + + + /** + 发送统计微博 + + @param weibos UMSocialWeibo对象组成的数组 + @param appKey 友盟appkey + @param topic 话题,可选,可以设置为nil + @parma completion 发送完成的事件处理block + + */ + //+(void)postWeiboCounts:(NSArray *)weibos appKey:(NSString *)appKey topic:(NSString *)topic completion:(MobClickSocialAnalyticsCompletion)completion; + //@end + @Method(selector = "postWeiboCounts:appKey:topic:completion:") + public native static void postWeiboCounts(List weibos, String appKey, String topic, @Block MobClickSocialAnalyticsCompletion completion); +} diff --git a/umenganalysics/MobClickSocialAnalyticsCompletion.java b/umenganalysics/MobClickSocialAnalyticsCompletion.java new file mode 100644 index 0000000..ef2f4fe --- /dev/null +++ b/umenganalysics/MobClickSocialAnalyticsCompletion.java @@ -0,0 +1,8 @@ +package net.mwplay.umenganalysics; + +import org.robovm.apple.foundation.NSDictionary; +import org.robovm.apple.foundation.NSError; + +public interface MobClickSocialAnalyticsCompletion { + void invoke(NSDictionary response, NSError error); +} diff --git a/umenganalysics/MobClickSocialWeibo.java b/umenganalysics/MobClickSocialWeibo.java new file mode 100644 index 0000000..49f7b0a --- /dev/null +++ b/umenganalysics/MobClickSocialWeibo.java @@ -0,0 +1,163 @@ +package net.mwplay.umenganalysics; + +import org.robovm.apple.foundation.NSDictionary; +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.ByVal; +import org.robovm.rt.bro.annotation.GlobalValue; +import org.robovm.rt.bro.annotation.Library; +import org.robovm.rt.bro.annotation.Pointer; + +@Library(Library.INTERNAL) +@NativeClass +public class MobClickSocialWeibo extends NSObject { +// typedef NSString * MobClickSocialTypeString; +// +// extern MobClickSocialTypeString const MobClickSocialTypeSina; //新浪微博 +// extern MobClickSocialTypeString const MobClickSocialTypeTencent; //腾讯微博 +// extern MobClickSocialTypeString const MobClickSocialTypeRenren; //人人网 +// extern MobClickSocialTypeString const MobClickSocialTypeQzone; //Qzone +// extern MobClickSocialTypeString const MobClickSocialTypeRenren; //人人网 +// extern MobClickSocialTypeString const MobClickSocialTypeDouban; //douban +// extern MobClickSocialTypeString const MobClickSocialTypeWxsesion; //微信好友分享 +// extern MobClickSocialTypeString const MobClickSocialTypeWxtimeline; //微信朋友圈 +// extern MobClickSocialTypeString const MobClickSocialTypeHuaban; //花瓣 +// extern MobClickSocialTypeString const MobClickSocialTypeKaixin; //开心 +// extern MobClickSocialTypeString const MobClickSocialTypeFacebook; //facebook +// extern MobClickSocialTypeString const MobClickSocialTypeTwitter; //twitter +// extern MobClickSocialTypeString const MobClickSocialTypeInstagram; //instagram +// extern MobClickSocialTypeString const MobClickSocialTypeFlickr; //flickr +// extern MobClickSocialTypeString const MobClickSocialTypeQQ; //qq +// extern MobClickSocialTypeString const MobClickSocialTypeWxfavorite; //微信收藏 +// extern MobClickSocialTypeString const MobClickSocialTypeLwsession; //来往 +// extern MobClickSocialTypeString const MobClickSocialTypeLwtimeline; //来往动态 +// extern MobClickSocialTypeString const MobClickSocialTypeYxsession; //易信 +// extern MobClickSocialTypeString const MobClickSocialTypeYxtimeline; //易信朋友圈 +// + @GlobalValue(symbol = "MobClickSocialTypeSina", optional=true) + public static native @ByVal String MobClickSocialTypeSina(); + + @GlobalValue(symbol = "MobClickSocialTypeTencent", optional=true) + public static native @ByVal String MobClickSocialTypeTencent(); + + @GlobalValue(symbol = "MobClickSocialTypeRenren", optional=true) + public static native @ByVal String MobClickSocialTypeRenren(); + + @GlobalValue(symbol = "MobClickSocialTypeQzone", optional=true) + public static native @ByVal String MobClickSocialTypeQzone(); + + @GlobalValue(symbol = "MobClickSocialTypeDouban", optional=true) + public static native @ByVal String MobClickSocialTypeDouban(); + + @GlobalValue(symbol = "MobClickSocialTypeWxsesion", optional=true) + public static native @ByVal String MobClickSocialTypeWxsesion(); + + @GlobalValue(symbol = "MobClickSocialTypeWxtimeline", optional=true) + public static native @ByVal String MobClickSocialTypeWxtimeline(); + + @GlobalValue(symbol = "MobClickSocialTypeHuaban", optional=true) + public static native @ByVal String MobClickSocialTypeHuaban(); + + @GlobalValue(symbol = "MobClickSocialTypeKaixin", optional=true) + public static native @ByVal String MobClickSocialTypeKaixin(); + + @GlobalValue(symbol = "MobClickSocialTypeFacebook", optional=true) + public static native @ByVal String MobClickSocialTypeFacebook(); + + @GlobalValue(symbol = "MobClickSocialTypeTwitter", optional=true) + public static native @ByVal String MobClickSocialTypeTwitter(); + + @GlobalValue(symbol = "MobClickSocialTypeInstagram", optional=true) + public static native @ByVal String MobClickSocialTypeInstagram(); + + @GlobalValue(symbol = "MobClickSocialTypeFlickr", optional=true) + public static native @ByVal String MobClickSocialTypeFlickr(); + + @GlobalValue(symbol = "MobClickSocialTypeQQ", optional=true) + public static native @ByVal String MobClickSocialTypeQQ(); + + @GlobalValue(symbol = "MobClickSocialTypeWxfavorite", optional=true) + public static native @ByVal String MobClickSocialTypeWxfavorite(); + + @GlobalValue(symbol = "MobClickSocialTypeLwsession", optional=true) + public static native @ByVal String MobClickSocialTypeLwsession(); + + @GlobalValue(symbol = "MobClickSocialTypeYxsession", optional=true) + public static native @ByVal String MobClickSocialTypeYxsession(); + + @GlobalValue(symbol = "MobClickSocialTypeYxtimeline", optional=true) + public static native @ByVal String MobClickSocialTypeYxtimeline(); + + @GlobalValue(symbol = "MobClickSocialTypeLwtimeline", optional=true) + public static native @ByVal String MobClickSocialTypeLwtimeline(); + + /** + * 微博平台类型,使用上面定义的几种常量字符串 + */ + // @property (nonatomic, copy) NSString *platformType; + @Property(selector = "platformType") + public native String getPlatformType(); + + @Property(selector = "setPlatformType:") + public native void setDelegate(String platformType); + + /** + * 微博id + */ + // @property (nonatomic, copy) NSString *weiboId; + @Property(selector = "weiboId") + public native String getWeiboId(); + + @Property(selector = "setWeiboId:") + public native void setWeiboId(String weiboId); + + /** + * 用户在微博平台的id + */ + // @property (nonatomic, copy) NSString *userId; + @Property(selector = "userId") + public native String getUserId(); + + @Property(selector = "setUserId:") + public native void setUserId(String userId); + + /** + * 微博平台的自定义字段,例如定义{‘gender’:0,’name’:’xxx’} + */ + // @property (nonatomic, strong) NSDictionary *param; + @Property(selector = "param") + public native String getParam(); + + @Property(selector = "setParam:") + public native void setParam(NSDictionary param); + + /** + * 初始化方法,在发送微博结束的回调方法使用此初始化方法 + * + * @param platformType + * 微博平台类型 + * @param weiboId + * 微博id,可以设置为nil + * @param userId + * 用户id + * @param param + * 微博平台自定义字段,可以设置为nil + * @return 微博对象 + */ + // -(id)initWithPlatformType:(MobClickSocialTypeString)platformType + // weiboId:(NSString *)weiboId usid:(NSString *)usid param:(NSDictionary + // *)param; + @Method(selector = "initWithPlatformType:weiboId:usid:param:") + public native @Pointer long init(String platformType, String weiboId, String usid, NSDictionary param); + + public MobClickSocialWeibo() { + } + + public MobClickSocialWeibo(String platformType, String weiboId, String usid, NSDictionary param) { + super((SkipInit)null); + initObject(init(platformType, weiboId, usid, param)); + } + // @end +} diff --git a/umenganalysics/ReportPolicy.java b/umenganalysics/ReportPolicy.java new file mode 100644 index 0000000..1c32b10 --- /dev/null +++ b/umenganalysics/ReportPolicy.java @@ -0,0 +1,30 @@ +package net.mwplay.umenganalysics; + +import org.robovm.rt.bro.ValuedEnum; + +//typedef enum { +// REALTIME = 0, //实时发送 (只在测试模式下有效) +// BATCH = 1, //启动发送 +// SEND_INTERVAL = 6, //最小间隔发送 ([90-86400]s, default 90s) +// +// // deprecated strategy: +// SENDDAILY = 4, //每日发送 (not available) +// SENDWIFIONLY = 5, //仅在WIFI下时启动发送 (not available) +// SEND_ON_EXIT = 7 //进入后台时发送 (not avilable, will be support later) +//} ReportPolicy; + +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; + } +} \ No newline at end of file