ViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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 "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. //对应文档中给的参数:appId,channelId,adFlag
  32. [GameSDK.sharedSDK initWithParameter:@"appid|channelId|appinfo" complete:^(NSError * error) {
  33. // 如果error不为空,初始化失败
  34. // 请使用error.localizedDescription和error.code确定错误原因.
  35. }];
  36. // 主动登录帐号
  37. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  38. // 如果error不为空,登录失败
  39. // 请使用error.localizedDescription和error.code确定错误原因.
  40. }];
  41. // 主动登出帐号
  42. [GameSDK.sharedSDK logoutWithComplete:^{
  43. // 登出成功.
  44. }];
  45. // 注册登出游戏的方法(注意引用循环)
  46. [GameSDK.sharedSDK logoutWhenNotification:^{
  47. //SDK要求游戏切换到登录页.
  48. }];
  49. // 主动切换帐号
  50. [GameSDK.sharedSDK logoutWithComplete:^{
  51. [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
  52. // 如果error不为空,登录失败
  53. // 请使用error.localizedDescription和error.code确定错误原因.
  54. }];
  55. }];
  56. // 生成订单信息
  57. id order = @{
  58. @"orderId": NSUUID.UUID.UUIDString,
  59. @"productCode": @"648",
  60. @"amount": @"648",
  61. @"productName": @"648元宝",
  62. @"serverId": @"1",
  63. @"roleName": @"用户",
  64. @"roleLevel": @"1",
  65. @"virtualCurrencyAmount": @"6480",
  66. @"extraInfo": @"11"
  67. };
  68. // 主动下单
  69. [GameSDK.sharedSDK buy:order complete:^(id info, NSError * error) {
  70. // 如果error不为空购买失败, 请使用error.localizedDescription和error.code确定错误原因
  71. }];
  72. // 主动上报角色信息
  73. [GameSDK.sharedSDK reportWithRoleName:@"Suave"
  74. level:60
  75. serverId:@"结伴同游"];
  76. //
  77. }
  78. - (void)loadView {
  79. [super loadView];
  80. KL* view = [[KL alloc] initWithFrame:self.view.frame];
  81. CAGradientLayer* gr = (id)view.layer;
  82. gr.colors = @[(__bridge id)UIColor.orangeColor.CGColor,
  83. (__bridge id)UIColor.purpleColor.CGColor];
  84. view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  85. [self.view insertSubview:view atIndex:0];
  86. }
  87. - (void)viewDidLoad {
  88. [super viewDidLoad];
  89. // Do any additional setup after loading the view, typically from a nib.
  90. //[self active:nil];
  91. NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
  92. //注册登出通知
  93. [center addObserver:self selector:@selector(logoutNotification:) name:@"LogoutNotificaion" object:nil];
  94. //注册登录通知
  95. [center addObserver:self selector:@selector(loginSuccessNotificaion:) name:@"LoginSuccessNotificaion" object:nil];
  96. }
  97. #pragma Test
  98. -(void)logoutNotification:(NSNotification *)noti {
  99. NSLog(@"登出成功通知~~~");
  100. }
  101. -(void)loginSuccessNotificaion:(NSNotification *)noti {
  102. NSLog(@"登录成功通知~~~");
  103. NSDictionary *dict = noti.userInfo;
  104. NSLog(@"dict=%@",dict);
  105. }
  106. - (void)extracted {
  107. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  108. NSLog(@"SDK初始化成功");
  109. }];
  110. }
  111. - (IBAction)active:(id)sender {
  112. //测试使用
  113. #define NT 0
  114. #if NT == 0
  115. // 正式环境
  116. //@"20194|1104|475316&iOScsyx_test_0001"
  117. //
  118. [XenonSDK.sharedSDK initWithParameter:@"20303|1105|910260&fscsIOS_IOS_0001" complete:^(NSError * error) {
  119. [self extracted];
  120. }];
  121. #endif
  122. #if NT == 1
  123. // 测试环境x
  124. [XenonSDK.sharedSDK setBaseURL:@"http://ta.funcheergame.com"];
  125. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  126. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  127. NSLog(@"%s %@", __func__, error);
  128. }];
  129. }];
  130. #endif
  131. #if NT == 2
  132. // 开发环境
  133. [XenonSDK.sharedSDK setBaseURL:@"http://192.168.1.116:9099"];
  134. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
  135. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  136. NSLog(@"%s %@", __func__, error);
  137. }];
  138. }];
  139. #endif
  140. #if NT == 3
  141. // 海外环境
  142. [XenonSDK.sharedSDK setBaseURL:@"https://abundant.sincerevirtue.com"];
  143. [XenonSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
  144. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  145. NSLog(@"%s %@", __func__, error);
  146. }];
  147. }];
  148. #endif
  149. }
  150. - (IBAction)login:(id)sender {
  151. // [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
  152. // NSLog(@"登录成功返回结果%@:=========",user);
  153. // }];
  154. [XenonSDK.sharedSDK hAutoWithComplete:^(id user, NSError *error) {
  155. if(error == nil){
  156. NSLog(@"登录成功,user==%@",user);
  157. }else{
  158. NSLog(@"自动登录:error=%@",error);
  159. }
  160. }];
  161. }
  162. - (IBAction)logout:(id)sender {
  163. [XenonSDK.sharedSDK logoutWithComplete:^{
  164. NSLog(@"登出成功!");
  165. }];
  166. }
  167. - (IBAction)pay:(id)sender {
  168. id ps = @{
  169. @"amount": @"2.99",
  170. @"productName": @"2.99",
  171. @"productCode": @"1001",
  172. @"roleName": @"6元宝001",
  173. @"orderId": @"47",
  174. @"roleLevel ":@"1",
  175. @"serverId": @"2",
  176. @"extraInfo": @"47",
  177. @"virtualCurrencyAmount": @""
  178. };
  179. [XenonSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
  180. NSLog(@"支付成功返回订单结果%@:=========",order);
  181. NSLog(@"error===%@",error);
  182. }];
  183. }
  184. - (IBAction)userCenter:(id)sender {
  185. [XenonSDK.sharedSDK center];
  186. }
  187. - (IBAction)report:(id)sender {
  188. [XenonSDK.sharedSDK reportWithRoleName:@"Suave"
  189. level:60
  190. serverId:@"结伴同游"];
  191. }
  192. //清除缓存按钮
  193. - (IBAction)clean:(id)sender {
  194. //清除cookies
  195. NSHTTPCookie *cookie;
  196. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  197. for (cookie in [storage cookies]){
  198. [storage deleteCookie:cookie];
  199. }
  200. //清除UIWebView的缓存
  201. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  202. NSURLCache * cache = [NSURLCache sharedURLCache];
  203. [cache removeAllCachedResponses];
  204. [cache setDiskCapacity:0];
  205. [cache setMemoryCapacity:0];
  206. // // 清除所有缓存
  207. [NSUserDefaults resetStandardUserDefaults];
  208. [NSUserDefaults.standardUserDefaults synchronize];
  209. //
  210. // // 重新初始化
  211. // exit(0);
  212. // [self active:sender];
  213. }
  214. //TalkingData游戏运营统计测试
  215. - (IBAction)TDGameOperationTest:(UIButton *)sender {
  216. [XenonSDK.sharedSDK TDGameOperationsinitWithAppID:@"App ID" ChannelId:@"渠道 ID"];
  217. // [XenonSDK.sharedSDK TDregisterWithAccount:@"accountId" name:@"Andy"];
  218. // [XenonSDK.sharedSDK TDloginWithAccount:@"accountId" name:@"Andy"];
  219. // [XenonSDK.sharedSDK TDreportWithAccount:@"accountId" Name:@"Andy" Age:18 Gender:1];
  220. // [XenonSDK.sharedSDK TDreportWithAccount:@"accountId" name:@"Andy" level:1 server:@"XXX01"];
  221. //
  222. // [XenonSDK.sharedSDK TDonChargeRequst:@"324892434420122221" iapId:@"500元礼包_test" currencyAmount:6.0 currencyType:@"USD" virtualCurrencyAmount:100.0 paymentType:@"苹果支付"];
  223. // [XenonSDK.sharedSDK TDonChargeSuccess:@"324892434420122221"];
  224. // [XenonSDK.sharedSDK TDonEvent:@"登录" eventData:@{@"login":@"YES"}];
  225. }
  226. //TalkingData应用统计分析测试
  227. - (IBAction)TDApplicationAnaly:(UIButton *)sender {
  228. //1.init
  229. [XenonSDK.sharedSDK TDAnalyticsinitWithAppID:@"App ID" ChannelId:@"渠道 ID" backgroundSession:NO];
  230. //2.页面访问
  231. // [XenonSDK.sharedSDK TDAnalyticsTrackPageBegin:@"XXXVC"];
  232. // [XenonSDK.sharedSDK TDAnalyticsTrackPageEnd:@"XXXVC"];
  233. //
  234. // //3. 自定义事件
  235. // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID"];
  236. // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID" label:@"event_label"];
  237. // NSDictionary *dict = @{@"click":@"3"};
  238. // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID" label:@"event_label" parameters:dict];
  239. //
  240. // //4.1 支付-创建订单
  241. // [XenonSDK.sharedSDK TDAnalyticsCreateOrder:@"orderId" total:1000 currencyType:@"USD"];
  242. //
  243. // //4.2 支付-订单详情
  244. // [XenonSDK.sharedSDK TDAnalyticsAddItem:@"商品ID" category:@"商品Type" name:@"商品名称" unitPrice:1000 amount:3];
  245. //
  246. // //4.3 支付-成功下单
  247. // TalkingDataOrder *order = [[TalkingDataOrder alloc]init];
  248. // [XenonSDK.sharedSDK TDAnalyticsOnPlaceOrder:@"profileID" order:order];
  249. }
  250. //优量汇广告测试.
  251. - (IBAction)YlhAdTestAction:(id)sender {
  252. //2.2 优量汇全屏广告测试
  253. // [[XenonSDK sharedSDK] openYLHFullScreenAd:@"YLH_fullScreen001" callback:^(BOOL ready){
  254. // if (ready) {
  255. // NSLog(@"[优量汇广告]result:模板2插屏全屏广告加载成功!");
  256. // }else{
  257. // NSLog(@"[优量汇广告]result:模板2插屏全屏广告加载失败!");
  258. // }
  259. // }];
  260. //2.3 优量汇插屏广告测试
  261. // [[XenonSDK sharedSDK] openYLHInterstitialAd:@"YLH_Interstitial001" callback:^(BOOL ready) {
  262. // if (ready) {
  263. // NSLog(@"[优量汇广告]result:模板2插屏半屏广告加载成功!");
  264. // }else{
  265. // NSLog(@"[优量汇广告]result:模板2插屏半屏广告加载失败!");
  266. // }
  267. // }];
  268. //2.4 优量汇视频激励广告测试
  269. // [[XenonSDK sharedSDK] openYLHExpressRewardedVideoAd:@"rewardVideo001" callback:^(BOOL ready, BOOL reward) {
  270. //
  271. // NSString *str1 = ready? @"视频激励广告回调成功!":@"视频激励广告回调失败!";
  272. // NSLog(@"[优量汇广告]:%@",str1);
  273. // NSString *str2 = reward? @"广告观看完成,符合奖励条件!":@"广告未观看完成!";
  274. // NSLog(@"[优量汇广告]:%@",str2);
  275. //
  276. // }];
  277. //2.5 优量汇横幅广告测试
  278. // [[XenonSDK sharedSDK] openYLHExpressBannerAd:@"YLH_banner001" callback:^(BOOL ready) {
  279. // if (ready) {
  280. // NSLog(@"[优量汇广告]:横幅广告回调成功!");
  281. // }else{
  282. // NSLog(@"[优量汇广告]:横幅广告回调失败!");
  283. // }
  284. // }];
  285. //2.6 优量汇原生广告测试
  286. // CGFloat x = 0.f;
  287. // CGFloat y = 100.f;
  288. // CGFloat w1 = [UIScreen mainScreen].bounds.size.width;
  289. // CGFloat h1 = 90.f;
  290. // NSString *placementId = @"1080793303881448";
  291. // [[XenonSDK sharedSDK] openYLHExpressNativeAdWithPlacementId:placementId AdName:@"YLH_native001" Frame:CGRectMake(x, y, w1, h1) callback:^(BOOL ready) {
  292. // if (ready) {
  293. // NSLog(@"[优量汇广告]:原生广告回调成功!");
  294. // }else{
  295. // NSLog(@"[优量汇广告]:原生广告回调失败!");
  296. // }
  297. // }];
  298. //2.TopON插页广告测试
  299. // [XenonSDK.sharedSDK openTOPONInterstitialAd:@"TopOnInterstitial001" callback:^(BOOL ready) {
  300. // if (ready) {
  301. // NSLog(@"[TopOn广告]result:插屏广告加载成功!");
  302. // }else{
  303. // NSLog(@"[TopOn广告]result:插屏广告加载失败!");
  304. // }
  305. // }];
  306. //3.TopON视频激励广告测试
  307. // [XenonSDK.sharedSDK openTOPONRewardedVideoAd:@"TopOnRewarded001" callback:^(BOOL ready, BOOL reward) {
  308. //
  309. // NSLog(@"ready:%@, reward:%@",ready?@"yes":@"no", reward?@"yes":@"no");
  310. //
  311. // }];
  312. //4. TopON横幅广告
  313. // [XenonSDK.sharedSDK openTOPONExpressBannerAd:@"TopOnbanner001" callback:^(BOOL ready) {
  314. // if (ready) {
  315. // NSLog(@"[TopOn广告]result:横幅广告加载成功!");
  316. // }else{
  317. // NSLog(@"[TopOn广告]result:横幅广告加载失败!");
  318. // }
  319. // }];
  320. //5. TopOn原生广告测试
  321. // int x = 0;
  322. // int y = 64;
  323. // int w1 = 600;
  324. // int h1 = 400;
  325. // [XenonSDK.sharedSDK openTOPONNativeAdWithX:x Y:y width:w1 height:h1 adId:@"TopOn_native001" callback:^(BOOL ready) {
  326. //
  327. // NSLog(@"%@",ready?@"原生广告加载成功!":@"原生广告加载失败!");
  328. //
  329. // }];
  330. }
  331. //穿山甲广告测试
  332. - (IBAction)csjAdTest:(UIButton *)sender {
  333. //2.穿山甲全屏广告测试.
  334. // [XenonSDK.sharedSDK openBUDFullScreenVideoAd:@"BUD_fullScreen001" callback:^(BOOL ready) {
  335. // if (ready) {
  336. // NSLog(@"[穿山甲广告]result:全屏广告加载成功!");
  337. // }else{
  338. // NSLog(@"[穿山甲广告]result:全屏广告加载失败!");
  339. // }
  340. // }];
  341. //3.穿山甲插屏广告测试.
  342. // [XenonSDK.sharedSDK openBUDInterstitialAd:@"BUD_Interstitial001" width:200.f Height:200.f callback:^(BOOL ready) {
  343. // if (ready) {
  344. // NSLog(@"[穿山甲广告]result:插屏广告加载成功!");
  345. // }else{
  346. // NSLog(@"[穿山甲广告]result:插屏广告加载失败!");
  347. // }
  348. // }];
  349. //4.穿山甲新插屏广告测试
  350. // [XenonSDK.sharedSDK openBUDNewInterstitialAd:@"BUD_NEWInterstitial001" callback:^(BOOL ready) {
  351. //
  352. // if (ready) {
  353. // NSLog(@"[穿山甲广告]result:新插屏广告加载成功!");
  354. // }else{
  355. // NSLog(@"[穿山甲广告]result:新插屏广告加载失败!");
  356. // }
  357. // }];
  358. //3. 穿山甲视频激励广告测试.
  359. // [[XenonSDK sharedSDK] openBUDExpressRewardedVideoAd:@"BUD_rewarded001" callback:^(BOOL ready, BOOL giveReward) {
  360. // NSLog(@"广告准备状态:%hhd",ready);
  361. // NSLog(@"广告观看完整,发放奖励:%hhd",giveReward);
  362. // }];
  363. //4. 穿山甲横幅广告
  364. CGFloat WIDTH = [UIScreen mainScreen].bounds.size.width;
  365. //CGFloat HEIGHT = [UIScreen mainScreen].bounds.size.height;
  366. CGFloat w = WIDTH-80;
  367. CGFloat h = w/2;
  368. CGFloat x = (WIDTH-w)/2.0;
  369. CGFloat y = 100;
  370. [[XenonSDK sharedSDK] openBUDNativeBannerAd:@"CSJ_banner001" WithX:x Y:y Width:w Height:h callback:^(BOOL ready) {
  371. if (ready) {
  372. NSLog(@"[穿山甲广告]result:横幅广告回调成功!");
  373. }else{
  374. NSLog(@"[穿山甲广告]result:横幅广告回调失败!");
  375. }
  376. }];
  377. //5. 穿山甲原生广告
  378. // [[XenonSDK sharedSDK] openBUDNativeAd:@"BUD_native001" WidthCGRect:CGRectMake(200, 300, 600, 400) BUSize:7 callback:^(BOOL ready) {
  379. // if (ready) {
  380. // NSLog(@"[穿山甲广告]result:原生广告回调成功!");
  381. // }else{
  382. // NSLog(@"[穿山甲广告]result:原生广告回调失败!");
  383. // }
  384. // }];
  385. }
  386. //关闭穿山甲横幅广告
  387. - (IBAction)closeCSJBannerAd:(UIButton *)sender {
  388. [[XenonSDK sharedSDK]closeBUDBannerAd:@"CSJ_banner001"];
  389. }
  390. //自动登录
  391. - (IBAction)autoLoginTest:(UIButton *)sender {
  392. [XenonSDK.sharedSDK hAutoWithComplete:^(id user, NSError *error) {
  393. if (error != nil) {
  394. NSLog(@"登录失败,error=%@",error);
  395. return;
  396. }
  397. if (user) {
  398. [XenonSDK.sharedSDK showHudWith:@"登录成功!"];
  399. NSString *uid = [user valueForKey:@"uid"];
  400. NSLog(@"uid====%@",uid);
  401. }
  402. }];
  403. }
  404. @end