ViewController.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //
  2. // ViewController.m
  3. // NatureDemo
  4. //
  5. // Created by SAGESSE on 2019/1/20.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "ViewController.h"
  9. #import "XSTracker.h"
  10. #import "XSNetwork.h"
  11. @interface KL: UIView
  12. @end
  13. @implementation KL
  14. + (Class)layerClass {
  15. return CAGradientLayer.self;
  16. }
  17. @end
  18. @interface GameSDK : NSObject
  19. + (XenonSDK*)sharedSDK;
  20. @end
  21. @implementation GameSDK
  22. + (XenonSDK*)sharedSDK {
  23. return XenonSDK.sharedSDK;
  24. }
  25. @end
  26. @interface ViewController ()
  27. @end
  28. @implementation ViewController
  29. - (void)test {
  30. // 主动初始化SDK
  31. [GameSDK.sharedSDK initWithParameter:@"appid|channelId|appinfo" complete:^(NSError * error) {
  32. // 如果error不为空,初始化失败
  33. // 请使用error.localizedDescription和error.code确定错误原因.
  34. }];
  35. // 主动登录帐号
  36. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  37. // 如果error不为空,登录失败
  38. // 请使用error.localizedDescription和error.code确定错误原因.
  39. }];
  40. // 主动登出帐号
  41. [GameSDK.sharedSDK logoutWithComplete:^{
  42. // 登出成功
  43. }];
  44. // 注册登出游戏的方法(注意引用循环)
  45. [GameSDK.sharedSDK logoutWhenNotification:^{
  46. // SDK要求游戏切换到登录页,
  47. }];
  48. // 主动切换帐号
  49. [GameSDK.sharedSDK logoutWithComplete:^{
  50. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  51. // 如果error不为空,登录失败.
  52. // 请使用error.localizedDescription和error.code确定错误原因.
  53. }];
  54. }];
  55. // 生成订单信息
  56. id order = @{
  57. @"orderId": NSUUID.UUID.UUIDString,
  58. @"productCode": @"648",
  59. @"amount": @"648",
  60. @"productName": @"648元宝",
  61. @"serverId": @"1",
  62. @"roleName": @"用户",
  63. @"roleLevel": @"1",
  64. @"virtualCurrencyAmount": @"6480",
  65. @"extraInfo": @"11"
  66. };
  67. // 主动下单
  68. [GameSDK.sharedSDK buy:order complete:^(id info, NSError * error) {
  69. //如果error不为空购买失败, 请使用error.localizedDescription和error.code确定错误原因.
  70. }];
  71. // 主动上报角色信息
  72. [GameSDK.sharedSDK reportWithRoleName:@"Suave"
  73. level:60
  74. serverId:@"结伴同游"];
  75. }
  76. - (void)loadView {
  77. [super loadView];
  78. KL* view = [[KL alloc] initWithFrame:self.view.frame];
  79. CAGradientLayer* gr = (id)view.layer;
  80. gr.colors = @[(__bridge id)UIColor.orangeColor.CGColor,
  81. (__bridge id)UIColor.purpleColor.CGColor];
  82. view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  83. [self.view insertSubview:view atIndex:0];
  84. }
  85. - (void)viewDidLoad {
  86. [super viewDidLoad];
  87. // Do any additional setup after loading the view, typically from a nib.
  88. self.view.backgroundColor = [UIColor whiteColor];
  89. //[self active:nil];
  90. //功夫全靠画参数
  91. [XenonSDK.sharedSDK initWithParameter:@"20309|1105|534383&xsdmxios_IOS_0001" complete:^(NSError * error) {
  92. //登录
  93. if (error == nil) {
  94. NSLog(@"SDK初始化成功!");
  95. [XSNetwork showHudSuccess:@"SDK初始化成功!"];
  96. //检查是否有漏单
  97. [XenonSDK.sharedSDK checkOrderStatus];
  98. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  99. if (error == nil) {
  100. NSLog(@"登录成功!");
  101. [XSNetwork showHudSuccess:@"登录成功!"];
  102. }else{
  103. NSLog(@"登录失败,error==%@",error);
  104. [XSNetwork showHudSuccess:[NSString stringWithFormat:@"登录失败,error==%@",error]];
  105. }
  106. }];
  107. }
  108. }];
  109. }
  110. /**
  111. - (void)extracted {
  112. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  113. NSLog(@"SDK初始化成功");
  114. }];
  115. }
  116. - (IBAction)active:(id)sender {
  117. //测试使用
  118. #define NT 0
  119. #if NT == 0
  120. // 正式环境
  121. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
  122. [self extracted];
  123. }];
  124. #endif
  125. #if NT == 1
  126. // 测试环境x
  127. [XenonSDK.sharedSDK setBaseURL:@"http://ta.funcheergame.com"];
  128. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  129. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  130. NSLog(@"%s %@", __func__, error);
  131. }];
  132. }];
  133. #endif
  134. #if NT == 2
  135. // 开发环境
  136. [XenonSDK.sharedSDK setBaseURL:@"http://192.168.1.116:9099"];
  137. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  138. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  139. NSLog(@"%s %@", __func__, error);
  140. }];
  141. }];
  142. #endif
  143. #if NT == 3
  144. // 海外环境
  145. [XenonSDK.sharedSDK setBaseURL:@"https://abundant.sincerevirtue.com"];
  146. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
  147. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  148. NSLog(@"%s %@", __func__, error);
  149. }];
  150. }];
  151. #endif
  152. }
  153. */
  154. - (IBAction)login:(id)sender {
  155. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  156. NSLog(@"登录成功返回结果%@:=========",user);
  157. }];
  158. }
  159. - (IBAction)logout:(id)sender {
  160. [XenonSDK.sharedSDK logoutWithComplete:^{
  161. NSLog(@"退出成功");
  162. }];
  163. }
  164. - (IBAction)pay:(id)sender {
  165. id ps = @{
  166. @"amount": @"2.99",
  167. @"productName": @"180_test",
  168. @"productCode": @"1002",
  169. @"roleName": @"测试角色test0077",
  170. @"orderId": @"55116788525332",
  171. //@"roleLevel ":@"1",
  172. @"serverId": @"1",
  173. @"extraInfo": @"55116788332",
  174. @"virtualCurrencyAmount": @""
  175. };
  176. [XenonSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
  177. NSLog(@"支付成功返回订单结果%@:=========",order);
  178. NSLog(@"支付参数%@:=========",ps);
  179. }];
  180. }
  181. - (IBAction)userCenter:(id)sender {
  182. [XenonSDK.sharedSDK center];
  183. }
  184. //上报游戏角色.
  185. - (IBAction)report:(id)sender {
  186. [XenonSDK.sharedSDK reportWithRoleName:@"Suave"
  187. level:60
  188. serverId:@"结伴同游"];
  189. }
  190. //清除缓存.
  191. - (IBAction)clean:(id)sender {
  192. //清除cookies
  193. NSHTTPCookie *cookie;
  194. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  195. for (cookie in [storage cookies]){
  196. [storage deleteCookie:cookie];
  197. }
  198. //清除UIWebView的缓存
  199. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  200. NSURLCache * cache = [NSURLCache sharedURLCache];
  201. [cache removeAllCachedResponses];
  202. [cache setDiskCapacity:0];
  203. [cache setMemoryCapacity:0];
  204. }
  205. @end