ViewController.m 6.1 KB

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