123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- //
- // ViewController.m
- // NatureDemo
- //
- // Created by SAGESSE on 2019/1/20.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "ViewController.h"
- #import "XSUser.h"
- #import "XSNetwork.h"
- @interface KL: UIView
- @end
- @implementation KL
- + (Class)layerClass {
- return CAGradientLayer.self;
- }
- @end
- @interface GameSDK : NSObject
- + (XenonSDK*)sharedSDK;
- @end
- @implementation GameSDK
- + (XenonSDK*)sharedSDK {
- return XenonSDK.sharedSDK;
- }
- @end
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)test {
-
- // 主动初始化SDK
- //对应文档中给的参数:appId,channelId,adFlag
- [GameSDK.sharedSDK initWithParameter:@"appid|channelId|appinfo" complete:^(NSError * error) {
- // 如果error不为空,初始化失败
- // 请使用error.localizedDescription和error.code确定错误原因.
- }];
-
-
- // 主动登录帐号
- [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
- // 如果error不为空,登录失败
- // 请使用error.localizedDescription和error.code确定错误原因.
- }];
-
-
- // 主动登出帐号
- [GameSDK.sharedSDK logoutWithComplete:^{
- // 登出成功.
- }];
-
- // 注册登出游戏的方法(注意引用循环)
- [GameSDK.sharedSDK logoutWhenNotification:^{
- //SDK要求游戏切换到登录页.
- }];
-
-
- // 主动切换帐号
- [GameSDK.sharedSDK logoutWithComplete:^{
- [GameSDK.sharedSDK loginWithComplete:^(NSDictionary* user, NSError * error) {
- // 如果error不为空,登录失败
- // 请使用error.localizedDescription和error.code确定错误原因.
- }];
- }];
-
-
- // 生成订单信息
- id order = @{
- @"orderId": NSUUID.UUID.UUIDString,
- @"productCode": @"648",
- @"amount": @"648",
- @"productName": @"648元宝",
- @"serverId": @"1",
- @"roleName": @"用户",
- @"roleLevel": @"1",
- @"virtualCurrencyAmount": @"6480",
- @"extraInfo": @"11"
- };
-
- // 主动下单
- [GameSDK.sharedSDK buy:order complete:^(id info, NSError * error) {
- // 如果error不为空购买失败, 请使用error.localizedDescription和error.code确定错误原因
- }];
-
-
- // 主动上报角色信息
- [GameSDK.sharedSDK reportWithRoleName:@"Suave"
- level:60
- serverId:@"结伴同游"];
-
- //
- }
- - (void)loadView {
- [super loadView];
- KL* view = [[KL alloc] initWithFrame:self.view.frame];
- CAGradientLayer* gr = (id)view.layer;
- gr.colors = @[(__bridge id)UIColor.orangeColor.CGColor,
- (__bridge id)UIColor.purpleColor.CGColor];
- view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [self.view insertSubview:view atIndex:0];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- //[self active:nil];
-
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
- //注册登出通知
- [center addObserver:self selector:@selector(logoutNotification:) name:@"LogoutNotificaion" object:nil];
-
- //注册登录通知
- [center addObserver:self selector:@selector(loginSuccessNotificaion:) name:@"LoginSuccessNotificaion" object:nil];
-
- }
- #pragma Test
- -(void)logoutNotification:(NSNotification *)noti {
-
- NSLog(@"登出成功通知~~~");
-
- }
- -(void)loginSuccessNotificaion:(NSNotification *)noti {
-
- NSLog(@"登录成功通知~~~");
- NSDictionary *dict = noti.userInfo;
- NSLog(@"dict=%@",dict);
-
- }
- - (void)extracted {
- [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"SDK初始化成功");
- }];
- }
- - (IBAction)active:(id)sender {
-
- //测试使用
- #define NT 0
- #if NT == 0
- // 正式环境
- //@"20194|1104|475316&iOScsyx_test_0001"
- //
- [XenonSDK.sharedSDK initWithParameter:@"20303|1105|910260&fscsIOS_IOS_0001" complete:^(NSError * error) {
- [self extracted];
- }];
- #endif
- #if NT == 1
- // 测试环境x
- [XenonSDK.sharedSDK setBaseURL:@"http://ta.funcheergame.com"];
- [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
- [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@", __func__, error);
- }];
- }];
- #endif
- #if NT == 2
- // 开发环境
- [XenonSDK.sharedSDK setBaseURL:@"http://192.168.1.116:9099"];
- [XenonSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
- [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@", __func__, error);
- }];
- }];
- #endif
- #if NT == 3
- // 海外环境
- [XenonSDK.sharedSDK setBaseURL:@"https://abundant.sincerevirtue.com"];
- [XenonSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
- [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@", __func__, error);
- }];
- }];
- #endif
- }
- - (IBAction)login:(id)sender {
-
- // [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- // NSLog(@"登录成功返回结果%@:=========",user);
- // }];
-
- [XenonSDK.sharedSDK hAutoWithComplete:^(id user, NSError *error) {
-
-
- if(error == nil){
- NSLog(@"登录成功,user==%@",user);
- }else{
- NSLog(@"自动登录:error=%@",error);
- }
- }];
-
- }
- - (IBAction)logout:(id)sender {
-
- [XenonSDK.sharedSDK logoutWithComplete:^{
- NSLog(@"登出成功!");
- }];
-
- }
- - (IBAction)pay:(id)sender {
- id ps = @{
- @"amount": @"2.99",
- @"productName": @"2.99",
- @"productCode": @"1001",
- @"roleName": @"6元宝001",
- @"orderId": @"47",
- @"roleLevel ":@"1",
- @"serverId": @"2",
- @"extraInfo": @"47",
- @"virtualCurrencyAmount": @""
- };
-
-
- [XenonSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
- NSLog(@"支付成功返回订单结果%@:=========",order);
- NSLog(@"error===%@",error);
- }];
- }
- - (IBAction)userCenter:(id)sender {
- [XenonSDK.sharedSDK center];
- }
- - (IBAction)report:(id)sender {
-
- [XenonSDK.sharedSDK reportWithRoleName:@"Suave"
- level:60
- serverId:@"结伴同游"];
- }
- //清除缓存按钮
- - (IBAction)clean:(id)sender {
-
- //清除cookies
- NSHTTPCookie *cookie;
- NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
- for (cookie in [storage cookies]){
- [storage deleteCookie:cookie];
- }
-
- //清除UIWebView的缓存
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
- NSURLCache * cache = [NSURLCache sharedURLCache];
- [cache removeAllCachedResponses];
- [cache setDiskCapacity:0];
- [cache setMemoryCapacity:0];
-
- // // 清除所有缓存
- [NSUserDefaults resetStandardUserDefaults];
- [NSUserDefaults.standardUserDefaults synchronize];
- //
- // // 重新初始化
- // exit(0);
- // [self active:sender];
- }
- //TalkingData游戏运营统计测试
- - (IBAction)TDGameOperationTest:(UIButton *)sender {
-
- [XenonSDK.sharedSDK TDGameOperationsinitWithAppID:@"App ID" ChannelId:@"渠道 ID"];
- // [XenonSDK.sharedSDK TDregisterWithAccount:@"accountId" name:@"Andy"];
- // [XenonSDK.sharedSDK TDloginWithAccount:@"accountId" name:@"Andy"];
- // [XenonSDK.sharedSDK TDreportWithAccount:@"accountId" Name:@"Andy" Age:18 Gender:1];
- // [XenonSDK.sharedSDK TDreportWithAccount:@"accountId" name:@"Andy" level:1 server:@"XXX01"];
- //
- // [XenonSDK.sharedSDK TDonChargeRequst:@"324892434420122221" iapId:@"500元礼包_test" currencyAmount:6.0 currencyType:@"USD" virtualCurrencyAmount:100.0 paymentType:@"苹果支付"];
- // [XenonSDK.sharedSDK TDonChargeSuccess:@"324892434420122221"];
- // [XenonSDK.sharedSDK TDonEvent:@"登录" eventData:@{@"login":@"YES"}];
-
- }
- //TalkingData应用统计分析测试
- - (IBAction)TDApplicationAnaly:(UIButton *)sender {
-
- //1.init
- [XenonSDK.sharedSDK TDAnalyticsinitWithAppID:@"App ID" ChannelId:@"渠道 ID" backgroundSession:NO];
-
- //2.页面访问
- // [XenonSDK.sharedSDK TDAnalyticsTrackPageBegin:@"XXXVC"];
- // [XenonSDK.sharedSDK TDAnalyticsTrackPageEnd:@"XXXVC"];
- //
- // //3. 自定义事件
- // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID"];
- // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID" label:@"event_label"];
- // NSDictionary *dict = @{@"click":@"3"};
- // [XenonSDK.sharedSDK TDAnalyticsTrackEvent:@"eventID" label:@"event_label" parameters:dict];
- //
- // //4.1 支付-创建订单
- // [XenonSDK.sharedSDK TDAnalyticsCreateOrder:@"orderId" total:1000 currencyType:@"USD"];
- //
- // //4.2 支付-订单详情
- // [XenonSDK.sharedSDK TDAnalyticsAddItem:@"商品ID" category:@"商品Type" name:@"商品名称" unitPrice:1000 amount:3];
- //
- // //4.3 支付-成功下单
- // TalkingDataOrder *order = [[TalkingDataOrder alloc]init];
- // [XenonSDK.sharedSDK TDAnalyticsOnPlaceOrder:@"profileID" order:order];
-
-
- }
- //优量汇广告测试.
- - (IBAction)YlhAdTestAction:(id)sender {
-
- //2.2 优量汇全屏广告测试
- // [[XenonSDK sharedSDK] openYLHFullScreenAd:@"YLH_fullScreen001" callback:^(BOOL ready){
- // if (ready) {
- // NSLog(@"[优量汇广告]result:模板2插屏全屏广告加载成功!");
- // }else{
- // NSLog(@"[优量汇广告]result:模板2插屏全屏广告加载失败!");
- // }
- // }];
-
- //2.3 优量汇插屏广告测试
- // [[XenonSDK sharedSDK] openYLHInterstitialAd:@"YLH_Interstitial001" callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[优量汇广告]result:模板2插屏半屏广告加载成功!");
- // }else{
- // NSLog(@"[优量汇广告]result:模板2插屏半屏广告加载失败!");
- // }
- // }];
-
- //2.4 优量汇视频激励广告测试
- // [[XenonSDK sharedSDK] openYLHExpressRewardedVideoAd:@"rewardVideo001" callback:^(BOOL ready, BOOL reward) {
- //
- // NSString *str1 = ready? @"视频激励广告回调成功!":@"视频激励广告回调失败!";
- // NSLog(@"[优量汇广告]:%@",str1);
- // NSString *str2 = reward? @"广告观看完成,符合奖励条件!":@"广告未观看完成!";
- // NSLog(@"[优量汇广告]:%@",str2);
- //
- // }];
-
-
- //2.5 优量汇横幅广告测试
- // [[XenonSDK sharedSDK] openYLHExpressBannerAd:@"YLH_banner001" callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[优量汇广告]:横幅广告回调成功!");
- // }else{
- // NSLog(@"[优量汇广告]:横幅广告回调失败!");
- // }
- // }];
-
-
- //2.6 优量汇原生广告测试
- // CGFloat x = 0.f;
- // CGFloat y = 100.f;
- // CGFloat w1 = [UIScreen mainScreen].bounds.size.width;
- // CGFloat h1 = 90.f;
- // NSString *placementId = @"1080793303881448";
- // [[XenonSDK sharedSDK] openYLHExpressNativeAdWithPlacementId:placementId AdName:@"YLH_native001" Frame:CGRectMake(x, y, w1, h1) callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[优量汇广告]:原生广告回调成功!");
- // }else{
- // NSLog(@"[优量汇广告]:原生广告回调失败!");
- // }
- // }];
- //2.TopON插页广告测试
- // [XenonSDK.sharedSDK openTOPONInterstitialAd:@"TopOnInterstitial001" callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[TopOn广告]result:插屏广告加载成功!");
- // }else{
- // NSLog(@"[TopOn广告]result:插屏广告加载失败!");
- // }
- // }];
-
- //3.TopON视频激励广告测试
- // [XenonSDK.sharedSDK openTOPONRewardedVideoAd:@"TopOnRewarded001" callback:^(BOOL ready, BOOL reward) {
- //
- // NSLog(@"ready:%@, reward:%@",ready?@"yes":@"no", reward?@"yes":@"no");
- //
- // }];
-
-
- //4. TopON横幅广告
- // [XenonSDK.sharedSDK openTOPONExpressBannerAd:@"TopOnbanner001" callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[TopOn广告]result:横幅广告加载成功!");
- // }else{
- // NSLog(@"[TopOn广告]result:横幅广告加载失败!");
- // }
- // }];
-
- //5. TopOn原生广告测试
- // int x = 0;
- // int y = 64;
- // int w1 = 600;
- // int h1 = 400;
- // [XenonSDK.sharedSDK openTOPONNativeAdWithX:x Y:y width:w1 height:h1 adId:@"TopOn_native001" callback:^(BOOL ready) {
- //
- // NSLog(@"%@",ready?@"原生广告加载成功!":@"原生广告加载失败!");
- //
- // }];
- }
- //穿山甲广告测试
- - (IBAction)csjAdTest:(UIButton *)sender {
-
- //2.穿山甲全屏广告测试.
- // [XenonSDK.sharedSDK openBUDFullScreenVideoAd:@"BUD_fullScreen001" callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[穿山甲广告]result:全屏广告加载成功!");
- // }else{
- // NSLog(@"[穿山甲广告]result:全屏广告加载失败!");
- // }
- // }];
-
-
- //3.穿山甲插屏广告测试.
- // [XenonSDK.sharedSDK openBUDInterstitialAd:@"BUD_Interstitial001" width:200.f Height:200.f callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[穿山甲广告]result:插屏广告加载成功!");
- // }else{
- // NSLog(@"[穿山甲广告]result:插屏广告加载失败!");
- // }
- // }];
-
-
- //4.穿山甲新插屏广告测试
- // [XenonSDK.sharedSDK openBUDNewInterstitialAd:@"BUD_NEWInterstitial001" callback:^(BOOL ready) {
- //
- // if (ready) {
- // NSLog(@"[穿山甲广告]result:新插屏广告加载成功!");
- // }else{
- // NSLog(@"[穿山甲广告]result:新插屏广告加载失败!");
- // }
- // }];
-
-
- //3. 穿山甲视频激励广告测试.
- // [[XenonSDK sharedSDK] openBUDExpressRewardedVideoAd:@"BUD_rewarded001" callback:^(BOOL ready, BOOL giveReward) {
- // NSLog(@"广告准备状态:%hhd",ready);
- // NSLog(@"广告观看完整,发放奖励:%hhd",giveReward);
- // }];
-
-
- //4. 穿山甲横幅广告
- CGFloat WIDTH = [UIScreen mainScreen].bounds.size.width;
- //CGFloat HEIGHT = [UIScreen mainScreen].bounds.size.height;
- CGFloat w = WIDTH-80;
- CGFloat h = w/2;
- CGFloat x = (WIDTH-w)/2.0;
- CGFloat y = 100;
- [[XenonSDK sharedSDK] openBUDNativeBannerAd:@"CSJ_banner001" WithX:x Y:y Width:w Height:h callback:^(BOOL ready) {
- if (ready) {
- NSLog(@"[穿山甲广告]result:横幅广告回调成功!");
- }else{
- NSLog(@"[穿山甲广告]result:横幅广告回调失败!");
- }
- }];
-
-
- //5. 穿山甲原生广告
- // [[XenonSDK sharedSDK] openBUDNativeAd:@"BUD_native001" WidthCGRect:CGRectMake(200, 300, 600, 400) BUSize:7 callback:^(BOOL ready) {
- // if (ready) {
- // NSLog(@"[穿山甲广告]result:原生广告回调成功!");
- // }else{
- // NSLog(@"[穿山甲广告]result:原生广告回调失败!");
- // }
- // }];
-
-
- }
- //关闭穿山甲横幅广告
- - (IBAction)closeCSJBannerAd:(UIButton *)sender {
-
- [[XenonSDK sharedSDK]closeBUDBannerAd:@"CSJ_banner001"];
- }
- //自动登录
- - (IBAction)autoLoginTest:(UIButton *)sender {
-
- [XenonSDK.sharedSDK hAutoWithComplete:^(id user, NSError *error) {
-
- if (error != nil) {
- NSLog(@"登录失败,error=%@",error);
- return;
- }
-
- if (user) {
- [XenonSDK.sharedSDK showHudWith:@"登录成功!"];
- NSString *uid = [user valueForKey:@"uid"];
- NSLog(@"uid====%@",uid);
- }
- }];
- }
- @end
|