123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // ViewController.m
- // NatureDemo
- //
- // Created by SAGESSE on 2019/1/20.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "ViewController.h"
- @interface KL: UIView
- @end
- @implementation KL
- + (Class)layerClass {
- return CAGradientLayer.self;
- }
- @end
- @interface GameSDK : NSObject
- + (NatureSDK*)sharedSDK;
- @end
- @implementation GameSDK
- + (NatureSDK*)sharedSDK {
- return NatureSDK.sharedSDK;
- }
- @end
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)test {
-
- // 主动初始化SDK
- [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];
- }
- - (IBAction)active:(id)sender {
-
- #define NT 3
- #if NT == 0
- // 正式环境
- [NatureSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
- [NatureSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@", __func__, error);
- }];
- }];
- #endif
- #if NT == 1
- // 测试环境x
- [NatureSDK.sharedSDK setBaseURL:@"http://ta.funcheergame.com"];
- [NatureSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
- [NatureSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@", __func__, error);
- }];
- }];
- #endif
- #if NT == 2
- // 开发环境
- [NatureSDK.sharedSDK setBaseURL:@"http://192.168.1.116:9099"];
- [NatureSDK.sharedSDK initWithParameter:@"20194|1104|625350&iOScsyx_test_0001" complete:^(NSError * error) {
- [NatureSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@", __func__, error);
- }];
- }];
- #endif
- #if NT == 3
- // 海外环境
- [NatureSDK.sharedSDK setBaseURL:@"https://fapp.funcheergame.com"];
- [NatureSDK.sharedSDK initWithParameter:@"20194|1104|475316&iOScsyx_test_0001" complete:^(NSError * error) {
- [NatureSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@", __func__, error);
- }];
- }];
- #endif
- }
- - (IBAction)login:(id)sender {
-
- [NatureSDK.sharedSDK loginWithComplete:^(id user, NSError * error) {
- NSLog(@"%s %@/%@", __func__, error, user);
- }];
- }
- - (IBAction)logout:(id)sender {
-
- [NatureSDK.sharedSDK logoutWithComplete:^{
- NSLog(@"%s", __func__);
- }];
-
- }
- - (IBAction)pay:(id)sender {
-
- id ps = @{
- @"amount": @"6",
- @"productName": @"6元宝",
- @"productCode": @"6",
- @"roleName": @"roleName",
- @"orderId": NSUUID.UUID.UUIDString,
- @"serverId": @"serverId",
- @"extraInfo": @"extraInfo"
- };
- [NatureSDK.sharedSDK buy:ps complete:^(id order, NSError * error) {
- NSLog(@"%s %@/%@", __func__, error, order);
- }];
- }
- - (IBAction)userCenter:(id)sender {
- [NatureSDK.sharedSDK center];
- }
- - (IBAction)report:(id)sender {
-
- [NatureSDK.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
|