XSCollector.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // XSCollector.m
  3. // XenonSDK
  4. //
  5. // Created by SAGESSE on 2019/5/30.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "XSCollector.h"
  9. @interface XSCollector ()
  10. @property (nonatomic, strong) NSString* uid;
  11. @property (nonatomic, strong) TDGAProfile* account;
  12. @end
  13. @implementation XSCollector
  14. - (instancetype)init {
  15. if (self = [super init]) {
  16. //...
  17. }
  18. return self;
  19. }
  20. - (instancetype)initWithAppId:(id)appId gameId:(id)gameId {
  21. self = [super init];
  22. [TalkingDataAppCpa setVerboseLogDisabled];
  23. [TalkingDataGA setVerboseLogDisabled];
  24. [TalkingDataAppCpa init:appId withChannelId:gameId];
  25. [TalkingDataGA onStart:appId withChannelId:gameId];
  26. return self;
  27. }
  28. //单例
  29. + (instancetype)sharedManager {
  30. static XSCollector *manager = nil;
  31. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  32. NSString *appId = [infos objectForKey:@"TDappId"];
  33. NSString *gameId = [infos objectForKey:@"TDgameId"];
  34. static dispatch_once_t onceToken;
  35. dispatch_once(&onceToken, ^{
  36. if (appId.length== 0 || gameId.length== 0) {
  37. NSLog(@"TD参数配置错误:应用ID或渠道ID为空, 请检查plist参数配置!!!");
  38. manager = [[XSCollector alloc] initWithAppId:@"" gameId:@""];
  39. }else{
  40. manager = [[XSCollector alloc] initWithAppId:appId gameId:gameId];
  41. }
  42. });
  43. return manager;
  44. }
  45. XSCollector* sdk_XSCollector_shared;
  46. + (void)setShared:(XSCollector*)tracker {
  47. sdk_XSCollector_shared = tracker;
  48. }
  49. + (XSCollector*)shared {
  50. return sdk_XSCollector_shared;
  51. }
  52. ///// Get the unique identifier of talking data.
  53. - (NSString*)identifer {
  54. return [TalkingDataAppCpa getDeviceId];
  55. }
  56. /// Register a user for data analyzer.
  57. //account:设定帐户唯一标识,用于区分一个玩家,最多64个字符。其他调用依赖于此 ID。
  58. //name:帐户的显性名
  59. - (void)registerWithAccount:(NSString*)account name:(NSString*)name {
  60. self.uid = account;
  61. self.account = [TDGAProfile setProfile:account];
  62. [self.account setProfileName:name];
  63. [TalkingDataAppCpa onRegister:account];
  64. }
  65. /// Login a user for data analyzer.
  66. - (void)loginWithAccount:(NSString*)account name:(NSString*)name {
  67. self.uid = account;
  68. self.account = [TDGAProfile setProfile:account];
  69. [self.account setProfileName:name];
  70. [self.account setProfileType:kProfileRegistered];
  71. [TalkingDataAppCpa onLogin:account];
  72. }
  73. -(void)reportWithAccount:(NSString *)account name:(NSString *)name age:(int)age gender:(NSInteger)gender {
  74. self.uid = account;
  75. if (self.uid.length == 0) {
  76. NSLog(@"帐户Id为空!!!");
  77. return;
  78. }
  79. self.account = [TDGAProfile setProfile:account];
  80. [self.account setProfileName:name];
  81. [self.account setAge:age];
  82. [self.account setGender:gender];
  83. [self.account setProfileType:kProfileRegistered];
  84. [TalkingDataAppCpa onCreateRole:name];
  85. }
  86. /// Update account.
  87. - (void)reportWithAccount:(NSString*)account name:(NSString*)name level:(NSInteger)level server:(NSString*)server {
  88. if (self.uid.length == 0) {
  89. return;
  90. }
  91. TDGAProfile* fa = [TDGAProfile setProfile:self.uid];
  92. [fa setLevel:(int)level];
  93. [fa setProfileName:name];
  94. [fa setGameServer:server];
  95. [fa setProfileType:kProfileRegistered];
  96. [TalkingDataAppCpa onCreateRole:name];
  97. }
  98. //充值请求
  99. - (void)onChargeRequst:(NSString *)orderId
  100. iapId:(NSString *)iapId
  101. currencyAmount:(double)currencyAmount
  102. currencyType:(NSString *)currencyType
  103. virtualCurrencyAmount:(double)virtualCurrencyAmount
  104. paymentType:(NSString *)paymentType {
  105. [TDGAVirtualCurrency onChargeRequst:orderId
  106. iapId:iapId
  107. currencyAmount:currencyAmount
  108. currencyType:currencyType
  109. virtualCurrencyAmount:virtualCurrencyAmount
  110. paymentType:paymentType];
  111. }
  112. //充值成功,确认玩家支付成功时调用.
  113. - (void)onChargeSuccess:(NSString *)orderId {
  114. [TDGAVirtualCurrency onChargeSuccess:orderId];
  115. }
  116. //TD 自定义事件
  117. -(void)onEvent:(NSString *)eventId eventData:(id)parm {
  118. [TalkingDataGA onEvent:eventId eventData:parm];
  119. }
  120. @end