MainViewController.m 5.94 KB
//
//  MainViewController.m
//  Demo_qiyu
//
//  Created by 许 on 17/6/7.
//  Copyright © 2017年 winFan. All rights reserved.
//

#import "MainViewController.h"
#import <PoolSdk/PoolSdk2.h>

@interface MainViewController ()

@end

NSString* sdkUserId = @"";

@implementation MainViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveSDKMessage:) name:poolSDK_Notification object:nil];
    // Do any additional setup after loading the view.
    NSLog(@"viewDidLoad");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)receiveSDKMessage:(NSNotification *)notification
{
    PoolSDKResult *result = [notification object];
    if (result) {
        NSLog(@"notiType:%d",result.notiType);
        switch (result.notiType) {
                
            case PoolSDKNotificationInitSDK:
            {
                NSLog(@"sdk初始化成功");
            }
                
                break;
            case PoolSDKNotificationLogin:
            {
                NSLog(@"result state:%d",result.statusCode);
                if (result.statusCode == POOLSDK_NO_ERROR) {
                    PoolLoginInfo *loginInfo = (PoolLoginInfo*)result.extendData;
                    sdkUserId = [loginInfo openId];
                    NSLog(@"收到登陆信息public openid:%@", [loginInfo openId]);
                    NSLog(@"收到登陆信息public token:%@", [loginInfo sign]);
                    NSLog(@"收到登陆信息public timestamp:%@", [loginInfo timestamp]);
                    NSLog(@"userType:%@",[loginInfo userType]);
                }else{
                    NSLog(@"%@",[result description]);
                }
            }
                break;
            case PoolSDKNotificationLogout:
            {
                NSLog(@"sdk注销成功,游戏处理");
            }
                break;
            case PoolSDKNotificationSwitchAccount:
                NSLog(@"切换账号通知");
                if (result.statusCode == POOLSDK_NO_ERROR) {
                    PoolLoginInfo *loginInfo = (PoolLoginInfo*)result.extendData;
                    NSLog(@"收到登陆信息public openid:%@", [loginInfo openId]);
                    NSLog(@"收到登陆信息public token:%@", [loginInfo sign]);
                    NSLog(@"收到登陆信息public timestamp:%@", [loginInfo timestamp]);
                    NSLog(@"userType:%@",[loginInfo userType]);
                }else{
                    NSLog(@"%@",[result description]);
                }
                break;
            default:
                break;
        }
    }
}

- (IBAction)actionInit:(id)sender {
    [[PoolSdk shareSDK]initSDK:self];
}
- (IBAction)actionLogin:(id)sender {
    [[PoolSdk shareSDK] loginSDK];
}

- (IBAction)actionPay:(id)sender {
    PoolCreateOrderInfo *payInfo = [[PoolCreateOrderInfo alloc]init];
    [payInfo setServerId:@"99887766"];
    [payInfo setPlayerName:@"iamrolename"];
    [payInfo setPlayerLevel:@"10"];
    [payInfo setUserId:sdkUserId];
    [payInfo setPostAmount:@"1"];
    [payInfo setProductId:@"com.xiongdi.xunqinji.6"];
    [payInfo setPlayerId:@"1231241234"];
    [payInfo setProductName:@"com.xiongdi.xunqinji.6"];
    [payInfo setProductDesc:@"productDes"];
    [payInfo setTimestamp:@"1232134"];
    [payInfo setExchange:@"10"];
    [payInfo setServerName:@"servername"];
    [payInfo setCustom:@"custom"];
    [[PoolSdk shareSDK] payWithPaymentInfo:payInfo];
}

-(NSString*)getCurrentTimestamp{
    // 时间戳转时间
    NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;
    NSString* timeStr = [[NSString alloc]initWithFormat:@"%.f",interval];
    return timeStr;
}

/**
 serverid
 servername
 roleid
 rolename
 rolelevel
*/
- (IBAction)actionSubmitRoleData:(id)sender {
    NSLog(@"数据接口");
    PoolReportInfo *reportInfo = [[PoolReportInfo alloc]init];
    [reportInfo setReportType:REPORT_ENTER];
    //[reportInfo setReportType:REPORT_CREATEROLE];
    //[reportInfo setReportType:REPORT_ROLEUPGRADE]
    [reportInfo setServerId:@"28"];
    [reportInfo setServerName:@"serverName"];
    [reportInfo setPlayerId:@"1231241234"];
    [reportInfo setPlayerName:@"playName"];
    [reportInfo setPlayerLevel:@"10"];
    [reportInfo setPartyName:@"1345"];
    [reportInfo setRoleCTime:[[NSNumber alloc]initWithLong:[self getCurrentTimestamp].longLongValue]];
    [reportInfo setRoleChangeTime:[[NSNumber alloc]initWithLong:[self getCurrentTimestamp].longLongValue]];
    [[PoolSdk shareSDK] reportSDK:reportInfo];
}

- (IBAction)actionLogout:(id)sender {
    NSLog(@"注销");
    if ([[PoolSdk shareSDK] hasLogout]) {
        [[PoolSdk shareSDK] logoutSDK];
    }
}

- (IBAction)actionSwitchAccount:(id)sender {
    if([[PoolSdk shareSDK] hasSwitchAccount]){
        [[PoolSdk shareSDK] switchAccount];
    }
}



#pragma mark - 截屏
- (void)screenShot:(UIView *)view{
    UIImage* image = nil;
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIGraphicsEndImageContext();
    if (image != nil) {
        NSLog(@"截图成功!");
        UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);
    }
}


#pragma mark - 保存到相册
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
{
    if(!error){
        NSLog(@"存到相册");
    }else{
        NSLog(@"存储失败");
        
    }
}




@end