ViewController.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. #import "NSBundle+KODLocalizable.h"
  11. #import "KODCommonConst.h"
  12. @interface KL: UIView
  13. @end
  14. @implementation KL
  15. + (Class)layerClass {
  16. return CAGradientLayer.self;
  17. }
  18. @end
  19. @interface GameSDK : NSObject
  20. + (XenonSDK*)sharedSDK;
  21. @end
  22. @implementation GameSDK
  23. + (XenonSDK*)sharedSDK {
  24. return XenonSDK.sharedSDK;
  25. }
  26. @end
  27. @interface ViewController ()
  28. @end
  29. @implementation ViewController
  30. - (void)test {
  31. // 主动初始化SDK
  32. //对应文档中给的参数:appId,channelId,adFlag
  33. [GameSDK.sharedSDK initWithParameter:@"appid|channelId|appinfo" complete:^(NSError * error) {
  34. // 如果error不为空,初始化失败
  35. // 请使用error.localizedDescription和error.code确定错误原因.
  36. }];
  37. // 主动登录帐号
  38. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  39. // 如果error不为空,登录失败
  40. // 请使用error.localizedDescription和error.code确定错误原因.
  41. }];
  42. // 主动登出帐号
  43. [GameSDK.sharedSDK logoutWithComplete:^{
  44. // 登出成功.
  45. }];
  46. // 注册登出游戏的方法(注意引用循环)
  47. [GameSDK.sharedSDK logoutWhenNotification:^{
  48. //SDK要求游戏切换到登录页.
  49. }];
  50. // 主动切换帐号
  51. [GameSDK.sharedSDK logoutWithComplete:^{
  52. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  53. // 如果error不为空,登录失败
  54. // 请使用error.localizedDescription和error.code确定错误原因.
  55. }];
  56. }];
  57. // 生成订单信息
  58. id order = @{
  59. @"orderId": NSUUID.UUID.UUIDString,
  60. @"productCode": @"648",
  61. @"amount": @"648",
  62. @"productName": @"648元宝",
  63. @"serverId": @"1",
  64. @"roleName": @"用户",
  65. @"roleLevel": @"1",
  66. @"virtualCurrencyAmount": @"6480",
  67. @"extraInfo": @"11"
  68. };
  69. // 主动下单
  70. [GameSDK.sharedSDK buy:order complete:^(id info, NSError * error) {
  71. // 如果error不为空购买失败, 请使用error.localizedDescription和error.code确定错误原因
  72. }];
  73. // 主动上报角色信息
  74. [GameSDK.sharedSDK reportWithRoleName:@"Suave"
  75. level:60
  76. serverId:@"结伴同游"];
  77. //
  78. }
  79. - (void)loadView {
  80. [super loadView];
  81. KL* view = [[KL alloc] initWithFrame:self.view.frame];
  82. CAGradientLayer* gr = (id)view.layer;
  83. gr.colors = @[(__bridge id)UIColor.orangeColor.CGColor,
  84. (__bridge id)UIColor.purpleColor.CGColor];
  85. view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  86. [self.view insertSubview:view atIndex:0];
  87. }
  88. - (void)viewDidLoad {
  89. [super viewDidLoad];
  90. // Do any additional setup after loading the view, typically from a nib.
  91. //[self active:nil];
  92. NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
  93. //注册登出通知
  94. [center addObserver:self selector:@selector(logoutNotification:) name:@"LogoutNotificaion" object:nil];
  95. //注册登录通知
  96. [center addObserver:self selector:@selector(loginSuccessNotificaion:) name:@"LoginSuccessNotificaion" object:nil];
  97. //NSString *str1 = @"测试1333";
  98. //NSString *contents = [NSBundle KOD_localizedStringForKey:ServiceErrorPleaseConnnectServicePhone];
  99. }
  100. #pragma Test
  101. -(void)logoutNotification:(NSNotification *)noti {
  102. NSLog(@"登出成功通知~~~");
  103. }
  104. -(void)loginSuccessNotificaion:(NSNotification *)noti {
  105. NSLog(@"登录成功通知~~~");
  106. NSDictionary *dict = noti.userInfo;
  107. NSLog(@"dict=%@",dict);
  108. }
  109. - (void)extracted {
  110. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  111. NSLog(@"SDK初始化成功");
  112. }];
  113. }
  114. - (IBAction)active:(id)sender {
  115. //测试使用
  116. #define NT 0
  117. #if NT == 0
  118. // 正式环境
  119. //@"20194|1104|475316&iOScsyx_test_0001"
  120. //
  121. [XenonSDK.sharedSDK initWithParameter:@"20303|1105|910260&fscsIOS_IOS_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. - (IBAction)login:(id)sender {
  154. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  155. NSLog(@"登录成功返回结果%@:=========",user);
  156. }];
  157. }
  158. - (IBAction)logout:(id)sender {
  159. [XenonSDK.sharedSDK logoutWithComplete:^{
  160. NSLog(@"登出成功!");
  161. }];
  162. }
  163. - (IBAction)pay:(id)sender {
  164. id ps = @{
  165. @"amount": @"2.99",
  166. @"productName": @"2.99",
  167. @"productCode": @"1001",
  168. @"roleName": @"6元宝001",
  169. @"orderId": @"47",
  170. @"roleLevel ":@"1",
  171. @"serverId": @"2",
  172. @"extraInfo": @"47",
  173. @"virtualCurrencyAmount": @""
  174. };
  175. [XenonSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
  176. NSLog(@"支付成功返回订单结果%@:=========",order);
  177. NSLog(@"支付参数%@:=========",ps);
  178. }];
  179. }
  180. - (IBAction)userCenter:(id)sender {
  181. [XenonSDK.sharedSDK center];
  182. }
  183. - (IBAction)report:(id)sender {
  184. [XenonSDK.sharedSDK reportWithRoleName:@"Suave"
  185. level:60
  186. serverId:@"结伴同游"];
  187. }
  188. - (IBAction)clean:(id)sender {
  189. //清除cookies
  190. NSHTTPCookie *cookie;
  191. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  192. for (cookie in [storage cookies]){
  193. [storage deleteCookie:cookie];
  194. }
  195. //清除UIWebView的缓存
  196. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  197. NSURLCache * cache = [NSURLCache sharedURLCache];
  198. [cache removeAllCachedResponses];
  199. [cache setDiskCapacity:0];
  200. [cache setMemoryCapacity:0];
  201. // // 清除所有缓存
  202. [NSUserDefaults resetStandardUserDefaults];
  203. [NSUserDefaults.standardUserDefaults synchronize];
  204. //
  205. // // 重新初始化
  206. // exit(0);
  207. // [self active:sender];
  208. }
  209. @end