ViewController.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 "XSUser.h"
  10. @interface KL: UIView
  11. @end
  12. @implementation KL
  13. + (Class)layerClass {
  14. return CAGradientLayer.self;
  15. }
  16. @end
  17. @interface GameSDK : NSObject
  18. + (XenonSDK*)sharedSDK;
  19. @end
  20. @implementation GameSDK
  21. + (XenonSDK*)sharedSDK {
  22. return XenonSDK.sharedSDK;
  23. }
  24. @end
  25. @interface ViewController ()
  26. @end
  27. @implementation ViewController
  28. - (void)test {
  29. // 主动初始化SDK
  30. //对应文档中给的参数:appId,channelId,adFlag
  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 active:nil];
  89. NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
  90. //注册登出通知
  91. [center addObserver:self selector:@selector(logoutNotification:) name:@"LogoutNotificaion" object:nil];
  92. //注册登录通知
  93. [center addObserver:self selector:@selector(loginSuccessNotificaion:) name:@"LoginSuccessNotificaion" object:nil];
  94. }
  95. #pragma Test
  96. -(void)logoutNotification:(NSNotification *)noti {
  97. NSLog(@"登出成功通知~~~");
  98. }
  99. -(void)loginSuccessNotificaion:(NSNotification *)noti {
  100. NSLog(@"登录成功通知~~~");
  101. NSDictionary *dict = noti.userInfo;
  102. NSLog(@"dict=%@",dict);
  103. }
  104. - (void)extracted {
  105. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  106. NSLog(@"SDK初始化成功");
  107. }];
  108. }
  109. - (IBAction)active:(id)sender {
  110. //测试使用
  111. #define NT 0
  112. #if NT == 0
  113. // 正式环境
  114. //@"20194|1104|475316&iOScsyx_test_0001"
  115. //
  116. [XenonSDK.sharedSDK initWithParameter:@"20303|1105|910260&fscsIOS_IOS_0001" complete:^(NSError * error) {
  117. [self extracted];
  118. }];
  119. #endif
  120. #if NT == 1
  121. // 测试环境x
  122. [XenonSDK.sharedSDK setBaseURL:@"http://ta.funcheergame.com"];
  123. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  124. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  125. NSLog(@"%s %@", __func__, error);
  126. }];
  127. }];
  128. #endif
  129. #if NT == 2
  130. // 开发环境
  131. [XenonSDK.sharedSDK setBaseURL:@"http://192.168.1.116:9099"];
  132. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  133. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  134. NSLog(@"%s %@", __func__, error);
  135. }];
  136. }];
  137. #endif
  138. #if NT == 3
  139. // 海外环境
  140. [XenonSDK.sharedSDK setBaseURL:@"https://abundant.sincerevirtue.com"];
  141. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
  142. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  143. NSLog(@"%s %@", __func__, error);
  144. }];
  145. }];
  146. #endif
  147. }
  148. - (IBAction)login:(id)sender {
  149. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  150. NSLog(@"登录成功返回结果%@:=========",user);
  151. }];
  152. }
  153. - (IBAction)logout:(id)sender {
  154. [XenonSDK.sharedSDK logoutWithComplete:^{
  155. NSLog(@"登出成功!");
  156. }];
  157. }
  158. - (IBAction)pay:(id)sender {
  159. id ps = @{
  160. @"amount": @"0.99",
  161. @"productName": @"6元宝001",
  162. @"productCode": @"fqcz006",
  163. @"roleName": @"6元宝test2",
  164. @"orderId": @"2021539638234857754199781436",
  165. @"roleLevel ":@"1",
  166. @"serverId": @"2",
  167. @"extraInfo": @"24:1105",
  168. @"virtualCurrencyAmount": @""
  169. };
  170. [XenonSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
  171. NSLog(@"支付成功返回订单结果%@:=========",order);
  172. NSLog(@"支付参数%@:=========",ps);
  173. }];
  174. }
  175. - (IBAction)userCenter:(id)sender {
  176. [XenonSDK.sharedSDK center];
  177. }
  178. - (IBAction)report:(id)sender {
  179. [XenonSDK.sharedSDK reportWithRoleName:@"Suave"
  180. level:60
  181. serverId:@"结伴同游"];
  182. }
  183. - (IBAction)clean:(id)sender {
  184. //清除cookies
  185. NSHTTPCookie *cookie;
  186. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  187. for (cookie in [storage cookies]){
  188. [storage deleteCookie:cookie];
  189. }
  190. //清除UIWebView的缓存
  191. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  192. NSURLCache * cache = [NSURLCache sharedURLCache];
  193. [cache removeAllCachedResponses];
  194. [cache setDiskCapacity:0];
  195. [cache setMemoryCapacity:0];
  196. // // 清除所有缓存
  197. [NSUserDefaults resetStandardUserDefaults];
  198. [NSUserDefaults.standardUserDefaults synchronize];
  199. //
  200. // // 重新初始化
  201. // exit(0);
  202. // [self active:sender];
  203. }
  204. @end