当前位置: 移动技术网 > IT编程>开发语言>.net > Unity3D 接入友盟统计 推送 IOS SDK

Unity3D 接入友盟统计 推送 IOS SDK

2020年07月09日  | 移动技术网IT编程  | 我要评论

Unity3D 接入友盟统计 推送 IOS SDK

游戏移动统计

  • 下载链接
  • 官方文档
  • 从 unity3d 中导出 xcode 工程
  • 将下载的 framework 加入到 xcode 工程中
  • 添加依赖库
libz.tbd    数据压缩
libsqlite3.tbd  数据缓存
CoreTelephony.framework 获取运营商标识
SystemConfiguration.framework   判断网络
UTDID.framework 用来获得设备标识ID组件。
  • 在友盟开发者中心新建一个 app 记住AppKey
  • 初始化友盟 sdk [UMConfigure initWithAppkey:@“Your appkey” channel:@“App Store”];
  • 设置是否需要打开调试日志 [UMConfigure setLogEnabled:YES];//设置打开日志
  • 设置当前场景类型 [MobClick setScenarioType:E_UM_GAME];
/** 初始化友盟所有组件产品
@param appKey 开发者在友盟官网申请的appkey.
@param channel 渠道标识,可设置nil表示"App Store".
*/
+ (void)initWithAppkey:(NSString *)appKey channel:(NSString *)channel;

示例代码
#import <UMCommon/UMCommon.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions {
 [UMConfigure setLogEnabled:YES];//设置打开日志
 [UMConfigure initWithAppkey:@"Your appkey" channel:@"App Store"];
 [MobClick setScenarioType:E_UM_GAME];
}

信息统计

  • 玩家账户设置
1.说明和用途

当玩家账户确定或更改时使用

2.接口函数
+ (void)setUserLevelId:(int)level;
参数:

参数	类型	描述	备注
level	int	玩家等级
  • 充值
充值
1.说明和用途
玩家支付货币兑换虚拟币,用于统计游戏的收入情况
2.接口函数
+ (void)pay:(double)cash source:(int)source coin:(double)coin;
+ (void)pay:(double)cash source:(int)source item:(NSString *)item amount:(int)amount price:(double)price;
参数:

参数	类型	描述	备注
cash	double	真实币数量	>=1的整数,最多只保存小数点后2位
source	int	支付渠道	1 ~ 99的整数, 其中1..8 是预定义含义(参考下表),其余数值需要在网站设置。
coin	double	虚拟币数量	1大于等于0的整数, 最多只保存小数点后2位
item	NSString	道具名称	非空字符串
amount	int	道具数量	大于0的整数
source对应的数字、含义如下表:

数值	含义
1	App Store
2	支付宝
3	网银
4	财付通
5	移动通信
6	联通通信
7	电信通信
8	paypal
  • 购买
购买
1.说明和用途
玩家用虚拟币兑换一定数量、价值的道具
2.接口函数
+ (void)buy:(NSString *)item amount:(int)amount price:(double)price;
参数:

参数	类型	描述	备注
item	NSString	道具名称	非空字符串
amount	int	道具数量	大于0的整数
price	double	道具单价	>=0
注意:

购买道具需要传递道具ID(名称)、数量(amount)、虚拟币数量coin(amount * price)。
  • 消耗
消耗
1.说明和用途
玩家使用道具的情况
2.接口函数
+ (void)use:(NSString *)item amount:(int)amount price:(double)price;
参数:

参数	类型	描述	备注
item	NSString	道具名称	非空字符串
amount	int	道具数量	大于0的整数
price	double	道具单价	>=0
注意:

购买道具需要传递道具ID(名称)、数量(amount)、虚拟币数量coin(amount * price)。
  • 额外奖励
额外奖励
1.说明和用途
游戏中发生的金币、道具赠送行为
2.接口函数
+ (void)bonus:(double)coin source:(int)source;
+ (void)bonus:(NSString *)item amount:(int)amount price:(double)price source:(int)source;
参数:

参数	类型	描述	备注
source	int	支付渠道	取值在 1~99 之间, 1~3 已经被预先定义(参考下表), 其余数值需要在网站设置含义
coin	double	虚拟币数量	1大于等于0的整数, 最多只保存小数点后2位
item	NSString	道具名称	非空字符串
amount	int	道具数量	大于0的整数
price	double	道具单价	>=0
source对应的数字、含义如下表:

数值	含义
1	玩家赠送
2	开发商赠送
3	游戏奖励
注意:

消耗道具需要传递道具ID(名称)、数量(amount)、虚拟币数量coin(amount * price)。
  • 玩家账户设置
玩家账户设置
1.说明和用途
当玩家账户确定或更改时使用
2.接口函数
+ (void)setUserLevelId:(int)level;
参数:

参数	类型	描述	备注
level	int	玩家等级
  • 关卡
1.说明和用途
记录玩家在游戏中的进度
2.接口函数
+ (void)startLevel:(NSString *)level;
+ (void)finishLevel:(NSString *)level;
+ (void)failLevel:(NSString *)level;
参数:

参数	类型	描述	备注
level	NSString	关卡id	非空字符串

消息推送

  • 下载链接
  • 官方文档
  • 将下载好的 framework 库添加到 xcode 工程中
  • 在 apple development 中为当前应用创建 Certificates Apple Push Server 服务
  • 导出 p12 证书
  • 在友盟开发者中心为当前应用添加推送功能 并上传推送证书
  • 导入依赖库
UserNotifications.framework
libz.tbd
libsqlite3.0.tbd
  • 项目配置
打开推送开关 
打开后台推送权限
  • 初始化
// Push组件基本功能配置
UMessageRegisterEntity * entity = [[UMessageRegisterEntity alloc] init];
//type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
entity.types = UMessageAuthorizationOptionBadge|UMessageAuthorizationOptionSound|UMessageAuthorizationOptionAlert;
[UNUserNotificationCenter currentNotificationCenter].delegate=self;
[UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:entity     completionHandler:^(BOOL granted, NSError * _Nullable error) {
 if (granted) {
 }else{
 }
}];
  • 处理前台收到消息的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
 NSDictionary * userInfo = notification.request.content.userInfo;
 if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
     //应用处于前台时的远程推送接受
     //关闭U-Push自带的弹出框
     [UMessage setAutoAlert:NO];
     //必须加这句代码
     [UMessage didReceiveRemoteNotification:userInfo];
     
 }else{
     //应用处于前台时的本地推送接受
 }
 //当应用处于前台时提示设置,需要哪个可以设置哪一个
 completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}
  • 处理后台点击通知的代理方法

  • 注册device token
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
if (![deviceToken isKindOfClass:[NSData class]]) return;
    const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
    NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                          ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                          ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                          ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
    NSLog(@"deviceToken:%@",hexToken);
    //1.2.7版本开始不需要用户再手动注册devicetoken,SDK会自动注册
    //传入的devicetoken是系统回调didRegisterForRemoteNotificationsWithDeviceToken的入参,切记
    [UMessage registerDeviceToken:deviceToken];
}
  • 测试
友盟开发者中添加测试设备
友盟开发者后台创建测试任务
发布测试任务

本文地址:https://blog.csdn.net/design_i/article/details/107186606

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网