ViewController.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. @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. [GameSDK.sharedSDK initWithParameter:@"appid|channelId|appinfo" complete:^(NSError * error) {
  31. // 如果error不为空,初始化失败
  32. // 请使用error.localizedDescription和error.code确定错误原因.
  33. }];
  34. // 主动登录帐号
  35. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  36. // 如果error不为空,登录失败
  37. // 请使用error.localizedDescription和error.code确定错误原因.
  38. }];
  39. // 主动登出帐号
  40. [GameSDK.sharedSDK logoutWithComplete:^{
  41. // 登出成功
  42. }];
  43. // 注册登出游戏的方法(注意引用循环)
  44. [GameSDK.sharedSDK logoutWhenNotification:^{
  45. // SDK要求游戏切换到登录页,
  46. }];
  47. // 主动切换帐号
  48. [GameSDK.sharedSDK logoutWithComplete:^{
  49. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  50. // 如果error不为空,登录失败.
  51. // 请使用error.localizedDescription和error.code确定错误原因.
  52. }];
  53. }];
  54. // 生成订单信息
  55. id order = @{
  56. @"orderId": NSUUID.UUID.UUIDString,
  57. @"productCode": @"648",
  58. @"amount": @"648",
  59. @"productName": @"648元宝",
  60. @"serverId": @"1",
  61. @"roleName": @"用户",
  62. @"roleLevel": @"1",
  63. @"virtualCurrencyAmount": @"6480",
  64. @"extraInfo": @"11"
  65. };
  66. // 主动下单
  67. [GameSDK.sharedSDK buy:order complete:^(id info, NSError * error) {
  68. //如果error不为空购买失败, 请使用error.localizedDescription和error.code确定错误原因.
  69. }];
  70. // 主动上报角色信息
  71. [GameSDK.sharedSDK reportWithRoleName:@"Suave"
  72. level:60
  73. serverId:@"结伴同游"];
  74. }
  75. - (void)loadView {
  76. [super loadView];
  77. KL* view = [[KL alloc] initWithFrame:self.view.frame];
  78. CAGradientLayer* gr = (id)view.layer;
  79. gr.colors = @[(__bridge id)UIColor.orangeColor.CGColor,
  80. (__bridge id)UIColor.purpleColor.CGColor];
  81. view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  82. [self.view insertSubview:view atIndex:0];
  83. }
  84. - (void)viewDidLoad {
  85. [super viewDidLoad];
  86. // Do any additional setup after loading the view, typically from a nib.
  87. self.view.backgroundColor = [UIColor whiteColor];
  88. //[self active:nil];
  89. //20309|1105|534383&xsdmxios_IOS_0001
  90. [XenonSDK.sharedSDK initWithParameter:@"20387|1105|673842&gfqkhIOS_IOS_0001" complete:^(NSError * error) {
  91. //登录
  92. // if (error == nil) {
  93. // [XenonSDK.sharedSDK GMAdSDKinit];
  94. // }
  95. // [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  96. //
  97. // NSLog(@"SDK初始化成功");
  98. // }];
  99. [[XenonSDK sharedSDK] xautoWithComplete:^(id user, NSError *error) {
  100. }];
  101. }];
  102. }
  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. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
  115. [self extracted];
  116. }];
  117. #endif
  118. #if NT == 1
  119. // 测试环境x
  120. [XenonSDK.sharedSDK setBaseURL:@"http://ta.funcheergame.com"];
  121. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  122. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  123. NSLog(@"%s %@", __func__, error);
  124. }];
  125. }];
  126. #endif
  127. #if NT == 2
  128. // 开发环境
  129. [XenonSDK.sharedSDK setBaseURL:@"http://192.168.1.116:9099"];
  130. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  131. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  132. NSLog(@"%s %@", __func__, error);
  133. }];
  134. }];
  135. #endif
  136. #if NT == 3
  137. // 海外环境
  138. [XenonSDK.sharedSDK setBaseURL:@"https://abundant.sincerevirtue.com"];
  139. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
  140. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  141. NSLog(@"%s %@", __func__, error);
  142. }];
  143. }];
  144. #endif
  145. }
  146. */
  147. - (IBAction)login:(id)sender {
  148. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  149. NSLog(@"登录成功返回结果%@:=========",user);
  150. }];
  151. }
  152. - (IBAction)logout:(id)sender {
  153. [XenonSDK.sharedSDK logoutWithComplete:^{
  154. NSLog(@"退出成功");
  155. }];
  156. }
  157. - (IBAction)pay:(id)sender {
  158. id ps = @{
  159. @"amount": @"6",
  160. @"productName": @"6元宝",
  161. @"productCode": @"6",
  162. @"roleName": @"roleName",
  163. @"orderId": NSUUID.UUID.UUIDString,
  164. @"serverId": @"serverId",
  165. @"extraInfo": @"extraInfo"
  166. };
  167. [XenonSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
  168. NSLog(@"支付成功返回订单结果%@:=========",order);
  169. NSLog(@"支付参数%@:=========",ps);
  170. }];
  171. }
  172. - (IBAction)userCenter:(id)sender {
  173. [XenonSDK.sharedSDK center];
  174. }
  175. //上报游戏角色.
  176. - (IBAction)report:(id)sender {
  177. [XenonSDK.sharedSDK reportWithRoleName:@"Suave"
  178. level:60
  179. serverId:@"结伴同游"];
  180. }
  181. //清除缓存.
  182. - (IBAction)clean:(id)sender {
  183. //清除cookies
  184. NSHTTPCookie *cookie;
  185. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  186. for (cookie in [storage cookies]){
  187. [storage deleteCookie:cookie];
  188. }
  189. //清除UIWebView的缓存
  190. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  191. NSURLCache * cache = [NSURLCache sharedURLCache];
  192. [cache removeAllCachedResponses];
  193. [cache setDiskCapacity:0];
  194. [cache setMemoryCapacity:0];
  195. }
  196. //打开横幅广告
  197. - (IBAction)adBanner:(id)sender {
  198. [[XenonSDK sharedSDK] adBanner:@"banner_001"];
  199. }
  200. //打开插页广告
  201. - (IBAction)adInner:(id)sender {
  202. [[XenonSDK sharedSDK] openInterstitialAd:@"interstital_Test001" callback:^(BOOL result) {
  203. if (result) {
  204. NSLog(@"YES");
  205. }else{
  206. NSLog(@"NO");
  207. }
  208. }];
  209. }
  210. //打开视频激励广告
  211. - (IBAction)adVideo:(id)sender {
  212. [[XenonSDK sharedSDK] openVideoAd:@"video_test01" callback:^(BOOL result) {
  213. if (result) {
  214. NSLog(@"用户看完视频了,可以发放奖励了");
  215. }else{
  216. NSLog(@"视频还没加载好");
  217. }
  218. //观看过程中退出
  219. }];
  220. }
  221. //关闭横幅广告
  222. - (IBAction)closeBanner:(id)sender {
  223. NSLog(@"关闭横幅广告");
  224. //横幅广告 name:banner 参数必须一致.
  225. [[XenonSDK sharedSDK] closeAd:@"banner"];
  226. }
  227. //打开原生广告
  228. - (IBAction)nativeAd:(id)sender {
  229. //PS:这里参数格式可以修改.按照这种格式修改(x,y,w,h)
  230. [[XenonSDK sharedSDK] openNativeAdWithCenterX:40 Y:40 width:240 height:150];
  231. }
  232. //关闭原生广告
  233. - (IBAction)closeNativeAd:(id)sender {
  234. //原生广告 name:native 参数必须一致.
  235. [[XenonSDK sharedSDK] closeAd:@"native"];
  236. }
  237. //广告是否可用
  238. - (IBAction)bannerIsReady:(id)sender {
  239. BOOL result = [[XenonSDK sharedSDK] isAvailableAd:@"video_test01"];
  240. if (result) {
  241. NSLog(@"广告已准备好.");
  242. }else{
  243. NSLog(@"广告未准备好.");
  244. }
  245. }
  246. ///工具测试API
  247. - (IBAction)TestApi:(id)sender {
  248. //1.手机震动接口调用
  249. // [[XenonSDK sharedSDK] iphoneVibrate];
  250. //2.跳转到appstore商店评论
  251. // [[XenonSDK sharedSDK] skipToAppsotreWithID:@"1435569339"];
  252. //3.初始化自动登录
  253. // [[XenonSDK sharedSDK] xautoWithComplete:^(id user, NSError *error) {
  254. //
  255. //
  256. // }];
  257. //4.初始化手动登录
  258. // [XenonSDK.sharedSDK logoutWithComplete:^{
  259. // NSLog(@"退出成功");
  260. // [[XenonSDK sharedSDK] manualLogin];
  261. // }];
  262. //5.统计事件
  263. //[XenonSDK.sharedSDK tjEvent:0x0110];
  264. [XenonSDK.sharedSDK tjEvent:0x0112 value:@"登录测试"];
  265. }
  266. @end