123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // XSCollector.m
- // XenonSDK
- //
- // Created by SAGESSE on 2019/5/30.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "XSCollector.h"
- @interface XSCollector ()
- @property (nonatomic, strong) NSString* uid;
- @property (nonatomic, strong) TDGAProfile* account;
- @end
- @implementation XSCollector
- - (instancetype)init {
- if (self = [super init]) {
- //...
- }
- return self;
- }
- - (instancetype)initWithAppId:(id)appId gameId:(id)gameId {
- self = [super init];
-
- [TalkingDataAppCpa setVerboseLogDisabled];
- [TalkingDataGA setVerboseLogDisabled];
-
- [TalkingDataAppCpa init:appId withChannelId:gameId];
- [TalkingDataGA onStart:appId withChannelId:gameId];
- return self;
- }
- //单例
- + (instancetype)sharedManager {
- static XSCollector *manager = nil;
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- NSString *appId = [infos objectForKey:@"TDappId"];
- NSString *gameId = [infos objectForKey:@"TDgameId"];
-
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- if (appId.length== 0 || gameId.length== 0) {
- NSLog(@"TD参数配置错误:应用ID或渠道ID为空, 请检查plist参数配置!!!");
- manager = [[XSCollector alloc] initWithAppId:@"" gameId:@""];
- }else{
- manager = [[XSCollector alloc] initWithAppId:appId gameId:gameId];
- }
-
- });
- return manager;
- }
- XSCollector* sdk_XSCollector_shared;
- + (void)setShared:(XSCollector*)tracker {
- sdk_XSCollector_shared = tracker;
- }
- + (XSCollector*)shared {
- return sdk_XSCollector_shared;
- }
- ///// Get the unique identifier of talking data.
- - (NSString*)identifer {
- return [TalkingDataAppCpa getDeviceId];
- }
- /// Register a user for data analyzer.
- //account:设定帐户唯一标识,用于区分一个玩家,最多64个字符。其他调用依赖于此 ID。
- //name:帐户的显性名
- - (void)registerWithAccount:(NSString*)account name:(NSString*)name {
-
- self.uid = account;
- self.account = [TDGAProfile setProfile:account];
- [self.account setProfileName:name];
-
- [TalkingDataAppCpa onRegister:account];
- }
- /// Login a user for data analyzer.
- - (void)loginWithAccount:(NSString*)account name:(NSString*)name {
-
- self.uid = account;
- self.account = [TDGAProfile setProfile:account];
- [self.account setProfileName:name];
- [self.account setProfileType:kProfileRegistered];
- [TalkingDataAppCpa onLogin:account];
- }
- -(void)reportWithAccount:(NSString *)account name:(NSString *)name age:(int)age gender:(NSInteger)gender {
- self.uid = account;
- if (self.uid.length == 0) {
- NSLog(@"帐户Id为空!!!");
- return;
- }
-
- self.account = [TDGAProfile setProfile:account];
- [self.account setProfileName:name];
- [self.account setAge:age];
- [self.account setGender:gender];
- [self.account setProfileType:kProfileRegistered];
-
- [TalkingDataAppCpa onCreateRole:name];
- }
- /// Update account.
- - (void)reportWithAccount:(NSString*)account name:(NSString*)name level:(NSInteger)level server:(NSString*)server {
-
- if (self.uid.length == 0) {
- return;
- }
-
- TDGAProfile* fa = [TDGAProfile setProfile:self.uid];
-
- [fa setLevel:(int)level];
- [fa setProfileName:name];
- [fa setGameServer:server];
- [fa setProfileType:kProfileRegistered];
-
- [TalkingDataAppCpa onCreateRole:name];
- }
- //充值请求
- - (void)onChargeRequst:(NSString *)orderId
- iapId:(NSString *)iapId
- currencyAmount:(double)currencyAmount
- currencyType:(NSString *)currencyType
- virtualCurrencyAmount:(double)virtualCurrencyAmount
- paymentType:(NSString *)paymentType {
-
- [TDGAVirtualCurrency onChargeRequst:orderId
- iapId:iapId
- currencyAmount:currencyAmount
- currencyType:currencyType
- virtualCurrencyAmount:virtualCurrencyAmount
- paymentType:paymentType];
-
- }
- //充值成功,确认玩家支付成功时调用.
- - (void)onChargeSuccess:(NSString *)orderId {
-
- [TDGAVirtualCurrency onChargeSuccess:orderId];
- }
- //TD 自定义事件
- -(void)onEvent:(NSString *)eventId eventData:(id)parm {
- [TalkingDataGA onEvent:eventId eventData:parm];
- }
- @end
|