ViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. }
  155. - (IBAction)logout:(id)sender {
  156. [XenonSDK.sharedSDK logoutWithComplete:^{
  157. NSLog(@"登出成功!");
  158. }];
  159. }
  160. - (IBAction)pay:(id)sender {
  161. id ps = @{
  162. @"amount": @"2.99",
  163. @"productName": @"2.99",
  164. @"productCode": @"1001",
  165. @"roleName": @"6元宝001",
  166. @"orderId": @"47",
  167. @"roleLevel ":@"1",
  168. @"serverId": @"2",
  169. @"extraInfo": @"47",
  170. @"virtualCurrencyAmount": @""
  171. };
  172. [XenonSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
  173. NSLog(@"支付成功返回订单结果%@:=========",order);
  174. NSLog(@"error===%@",error);
  175. }];
  176. }
  177. - (IBAction)userCenter:(id)sender {
  178. [XenonSDK.sharedSDK center];
  179. }
  180. - (IBAction)report:(id)sender {
  181. [XenonSDK.sharedSDK reportWithRoleName:@"Suave"
  182. level:60
  183. serverId:@"结伴同游"];
  184. }
  185. //清除缓存按钮
  186. - (IBAction)clean:(id)sender {
  187. //清除cookies
  188. NSHTTPCookie *cookie;
  189. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  190. for (cookie in [storage cookies]){
  191. [storage deleteCookie:cookie];
  192. }
  193. //清除UIWebView的缓存
  194. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  195. NSURLCache * cache = [NSURLCache sharedURLCache];
  196. [cache removeAllCachedResponses];
  197. [cache setDiskCapacity:0];
  198. [cache setMemoryCapacity:0];
  199. // // 清除所有缓存
  200. [NSUserDefaults resetStandardUserDefaults];
  201. [NSUserDefaults.standardUserDefaults synchronize];
  202. //
  203. // // 重新初始化
  204. // exit(0);
  205. // [self active:sender];
  206. }
  207. //TalkingData游戏运营统计测试
  208. - (IBAction)TDGameOperationTest:(UIButton *)sender {
  209. [XenonSDK.sharedSDK TDGameOperationsinitWithAppID:@"App ID" ChannelId:@"渠道 ID"];
  210. // [XenonSDK.sharedSDK TDregisterWithAccount:@"accountId" name:@"Andy"];
  211. // [XenonSDK.sharedSDK TDloginWithAccount:@"accountId" name:@"Andy"];
  212. // [XenonSDK.sharedSDK TDreportWithAccount:@"accountId" Name:@"Andy" Age:18 Gender:1];
  213. // [XenonSDK.sharedSDK TDreportWithAccount:@"accountId" name:@"Andy" level:1 server:@"XXX01"];
  214. //
  215. // [XenonSDK.sharedSDK TDonChargeRequst:@"324892434420122221" iapId:@"500元礼包_test" currencyAmount:6.0 currencyType:@"USD" virtualCurrencyAmount:100.0 paymentType:@"苹果支付"];
  216. // [XenonSDK.sharedSDK TDonChargeSuccess:@"324892434420122221"];
  217. // [XenonSDK.sharedSDK TDonEvent:@"登录" eventData:@{@"login":@"YES"}];
  218. }
  219. //TalkingData应用统计分析测试
  220. - (IBAction)TDApplicationAnaly:(UIButton *)sender {
  221. //1.init
  222. [XenonSDK.sharedSDK TDAnalyticsinitWithAppID:@"App ID" ChannelId:@"渠道 ID" backgroundSession:NO];
  223. //2.页面访问
  224. // [XenonSDK.sharedSDK TDAnalyticsTrackPageBegin:@"XXXVC"];
  225. // [XenonSDK.sharedSDK TDAnalyticsTrackPageEnd:@"XXXVC"];
  226. //
  227. // //3. 自定义事件
  228. // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID"];
  229. // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID" label:@"event_label"];
  230. // NSDictionary *dict = @{@"click":@"3"};
  231. // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID" label:@"event_label" parameters:dict];
  232. //
  233. // //4.1 支付-创建订单
  234. // [XenonSDK.sharedSDK TDAnalyticsCreateOrder:@"orderId" total:1000 currencyType:@"USD"];
  235. //
  236. // //4.2 支付-订单详情
  237. // [XenonSDK.sharedSDK TDAnalyticsAddItem:@"商品ID" category:@"商品Type" name:@"商品名称" unitPrice:1000 amount:3];
  238. //
  239. // //4.3 支付-成功下单
  240. // TalkingDataOrder *order = [[TalkingDataOrder alloc]init];
  241. // [XenonSDK.sharedSDK TDAnalyticsOnPlaceOrder:@"profileID" order:order];
  242. }
  243. //优量汇广告测试.
  244. - (IBAction)YlhAdTestAction:(id)sender {
  245. //2.2 优量汇全屏广告测试
  246. // [[XenonSDK sharedSDK] openYLHFullScreenAd:@"YLH_fullScreen001" callback:^(BOOL ready){
  247. // if (ready) {
  248. // NSLog(@"[优量汇广告]result:模板2插屏全屏广告加载成功!");
  249. // }else{
  250. // NSLog(@"[优量汇广告]result:模板2插屏全屏广告加载失败!");
  251. // }
  252. // }];
  253. //2.3 优量汇插屏广告测试
  254. // [[XenonSDK sharedSDK] openYLHInterstitialAd:@"YLH_Interstitial001" callback:^(BOOL ready) {
  255. // if (ready) {
  256. // NSLog(@"[优量汇广告]result:模板2插屏半屏广告加载成功!");
  257. // }else{
  258. // NSLog(@"[优量汇广告]result:模板2插屏半屏广告加载失败!");
  259. // }
  260. // }];
  261. //2.4 优量汇视频激励广告测试
  262. // [[XenonSDK sharedSDK] openYLHExpressRewardedVideoAd:@"rewardVideo001" callback:^(BOOL ready, BOOL reward) {
  263. //
  264. // NSString *str1 = ready? @"视频激励广告回调成功!":@"视频激励广告回调失败!";
  265. // NSLog(@"[优量汇广告]:%@",str1);
  266. // NSString *str2 = reward? @"广告观看完成,符合奖励条件!":@"广告未观看完成!";
  267. // NSLog(@"[优量汇广告]:%@",str2);
  268. //
  269. // }];
  270. //2.5 优量汇横幅广告测试
  271. // [[XenonSDK sharedSDK] openYLHExpressBannerAd:@"YLH_banner001" callback:^(BOOL ready) {
  272. // if (ready) {
  273. // NSLog(@"[优量汇广告]:横幅广告回调成功!");
  274. // }else{
  275. // NSLog(@"[优量汇广告]:横幅广告回调失败!");
  276. // }
  277. // }];
  278. //2.6 优量汇原生广告测试
  279. // CGFloat x = 0.f;
  280. // CGFloat y = 100.f;
  281. // CGFloat w1 = [UIScreen mainScreen].bounds.size.width;
  282. // CGFloat h1 = 90.f;
  283. // NSString *placementId = @"1080793303881448";
  284. // [[XenonSDK sharedSDK] openYLHExpressNativeAdWithPlacementId:placementId AdName:@"YLH_native001" Frame:CGRectMake(x, y, w1, h1) callback:^(BOOL ready) {
  285. // if (ready) {
  286. // NSLog(@"[优量汇广告]:原生广告回调成功!");
  287. // }else{
  288. // NSLog(@"[优量汇广告]:原生广告回调失败!");
  289. // }
  290. // }];
  291. //2.TopON插页广告测试
  292. // [XenonSDK.sharedSDK openTOPONInterstitialAd:@"TopOnInterstitial001" callback:^(BOOL ready) {
  293. // if (ready) {
  294. // NSLog(@"[TopOn广告]result:插屏广告加载成功!");
  295. // }else{
  296. // NSLog(@"[TopOn广告]result:插屏广告加载失败!");
  297. // }
  298. // }];
  299. //3.TopON视频激励广告测试
  300. // [XenonSDK.sharedSDK openTOPONRewardedVideoAd:@"TopOnRewarded001" callback:^(BOOL ready, BOOL reward) {
  301. //
  302. // NSLog(@"ready:%@, reward:%@",ready?@"yes":@"no", reward?@"yes":@"no");
  303. //
  304. // }];
  305. //4. TopON横幅广告
  306. // [XenonSDK.sharedSDK openTOPONExpressBannerAd:@"TopOnbanner001" callback:^(BOOL ready) {
  307. // if (ready) {
  308. // NSLog(@"[TopOn广告]result:横幅广告加载成功!");
  309. // }else{
  310. // NSLog(@"[TopOn广告]result:横幅广告加载失败!");
  311. // }
  312. // }];
  313. //5. TopOn原生广告测试
  314. // int x = 0;
  315. // int y = 64;
  316. // int w1 = 600;
  317. // int h1 = 400;
  318. // [XenonSDK.sharedSDK openTOPONNativeAdWithX:x Y:y width:w1 height:h1 adId:@"TopOn_native001" callback:^(BOOL ready) {
  319. //
  320. // NSLog(@"%@",ready?@"原生广告加载成功!":@"原生广告加载失败!");
  321. //
  322. // }];
  323. }
  324. //穿山甲广告测试
  325. - (IBAction)csjAdTest:(UIButton *)sender {
  326. //2.穿山甲全屏广告测试.
  327. // [XenonSDK.sharedSDK openBUDFullScreenVideoAd:@"BUD_fullScreen001" callback:^(BOOL ready) {
  328. // if (ready) {
  329. // NSLog(@"[穿山甲广告]result:全屏广告加载成功!");
  330. // }else{
  331. // NSLog(@"[穿山甲广告]result:全屏广告加载失败!");
  332. // }
  333. // }];
  334. //3.穿山甲插屏广告测试.
  335. // [XenonSDK.sharedSDK openBUDInterstitialAd:@"BUD_Interstitial001" width:200.f Height:200.f callback:^(BOOL ready) {
  336. // if (ready) {
  337. // NSLog(@"[穿山甲广告]result:插屏广告加载成功!");
  338. // }else{
  339. // NSLog(@"[穿山甲广告]result:插屏广告加载失败!");
  340. // }
  341. // }];
  342. //4.穿山甲新插屏广告测试
  343. // [XenonSDK.sharedSDK openBUDNewInterstitialAd:@"BUD_NEWInterstitial001" callback:^(BOOL ready) {
  344. //
  345. // if (ready) {
  346. // NSLog(@"[穿山甲广告]result:新插屏广告加载成功!");
  347. // }else{
  348. // NSLog(@"[穿山甲广告]result:新插屏广告加载失败!");
  349. // }
  350. // }];
  351. //3. 穿山甲视频激励广告测试.
  352. // [[XenonSDK sharedSDK] openBUDExpressRewardedVideoAd:@"BUD_rewarded001" callback:^(BOOL ready, BOOL giveReward) {
  353. // NSLog(@"广告准备状态:%hhd",ready);
  354. // NSLog(@"广告观看完整,发放奖励:%hhd",giveReward);
  355. // }];
  356. //4. 穿山甲横幅广告
  357. CGFloat WIDTH = [UIScreen mainScreen].bounds.size.width;
  358. //CGFloat HEIGHT = [UIScreen mainScreen].bounds.size.height;
  359. CGFloat w = WIDTH-80;
  360. CGFloat h = w/2;
  361. CGFloat x = (WIDTH-w)/2.0;
  362. CGFloat y = 100;
  363. [[XenonSDK sharedSDK] openBUDNativeBannerAd:@"CSJ_banner001" WithX:x Y:y Width:w Height:h callback:^(BOOL ready) {
  364. if (ready) {
  365. NSLog(@"[穿山甲广告]result:横幅广告回调成功!");
  366. }else{
  367. NSLog(@"[穿山甲广告]result:横幅广告回调失败!");
  368. }
  369. }];
  370. //5. 穿山甲原生广告
  371. // [[XenonSDK sharedSDK] openBUDNativeAd:@"BUD_native001" WidthCGRect:CGRectMake(200, 300, 600, 400) BUSize:7 callback:^(BOOL ready) {
  372. // if (ready) {
  373. // NSLog(@"[穿山甲广告]result:原生广告回调成功!");
  374. // }else{
  375. // NSLog(@"[穿山甲广告]result:原生广告回调失败!");
  376. // }
  377. // }];
  378. }
  379. //关闭穿山甲横幅广告
  380. - (IBAction)closeCSJBannerAd:(UIButton *)sender {
  381. [[XenonSDK sharedSDK]closeBUDBannerAd:@"CSJ_banner001"];
  382. }
  383. //自动登录
  384. - (IBAction)autoLoginTest:(UIButton *)sender {
  385. [XenonSDK.sharedSDK hAutoWithComplete:^(id user, NSError *error) {
  386. if (error != nil) {
  387. NSLog(@"登录失败,error=%@",error);
  388. return;
  389. }
  390. if (user) {
  391. [XenonSDK.sharedSDK showHudWith:@"登录成功!"];
  392. NSString *uid = [user valueForKey:@"uid"];
  393. NSLog(@"uid====%@",uid);
  394. }
  395. }];
  396. }
  397. @end