// // ViewController.m // NatureDemo // // Created by SAGESSE on 2019/1/20. // Copyright © 2019 SAGESSE. All rights reserved. // #import "ViewController.h" #import "XSUser.h" #import "NSBundle+KODLocalizable.h" #import "KODCommonConst.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]; //NSString *str1 = @"测试1333"; //NSString *contents = [NSBundle KOD_localizedStringForKey:ServiceErrorPleaseConnnectServicePhone]; } #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); }]; } - (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(@"支付参数%@:=========",ps); }]; } - (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]; } @end