PoolSdk.m 3.83 KB
//
//  PoolSdk.m
//  PoolSdk
//
//  Created by winFan on 11/23/15.
//  Copyright (c) 2015 winFan. All rights reserved.
//

#import "PoolSdk.h"
#import "SDKInterface.h"

static PoolSdk *s_PoolSdkCerterInstance = nil;
static id<UnionInterface>  _interface = nil;
@implementation PoolSdk : NSObject

- (id)init
{
    if(self = [super init])
    {
        _sdkVersion = [NSString stringWithFormat:@"%@ - %@",[[PoolConfig getInstance] gameSimpleName], [[PoolConfig getInstance] sdkSimpleName]];
        _interface = [[SDKInterface alloc] init];
        self.urlSchemes = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
    }
    return self;
}

- (void)initSDK :(UIViewController *) control
{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"pool_everLaunched"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"pool_everLaunched"];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"pool_firstLaunch"];
    }
    else{
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"pool_firstLaunch"];
    }
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
        
    }
    [_interface SDKinit:control];
    
    [[PoolChecker getInstance] reportSDKOpen];
    
    NSString* channelId = [[PoolConfig getInstance] getValueByKey:@"gamechannelid"];
    [TrackingIO initWithappKey:[[PoolConfig getInstance] getValueByKey:@"renyunAppKey"] withChannelId:channelId];
}

/**
 获取SDK实例对象
 */
+ (PoolSdk *)shareSDK
{
    static dispatch_once_t dgonceToken;
    dispatch_once(&dgonceToken, ^{
        s_PoolSdkCerterInstance = [[PoolSdk alloc] init];
        s_PoolSdkCerterInstance.sdkOrientation = ESDKOrientationLandscape;
        s_PoolSdkCerterInstance.bShowedFloat = NO;
    });
    
    return s_PoolSdkCerterInstance;
}

-(void)viewDidAppear{
    [_interface viewDidAppear];
}

- (void)loginSDK
{
    //[[PoolChecker getInstance] reportOpen];
    [_interface SDKloginSDK];
}

- (void)payWithPaymentInfo:(PoolCreateOrderInfo *)payInfo
{
    [_interface SDKpayWithPaymentInfo:payInfo];
}

- (void)reportSDK:(PoolReportInfo *)reportInfo
{
    NSString *reportT = [reportInfo reportType];
    reportInfo.openId = [[PoolChecker getInstance] userId];
    if ([reportT isEqualToString:REPORT_ENTER]) {
        [[PoolChecker getInstance] reportEnter:reportInfo];
        NSLog(@"reportSDK enter");
        [TrackingIO setLoginWithAccountID:[reportInfo playerId]];
    }else if ([reportT isEqualToString:REPORT_ROLEUPGRADE]){
        
    }else if ([reportT isEqualToString:REPORT_CREATEROLE]){
        NSLog(@"reportSDK createRole");
        [TrackingIO setRegisterWithAccountID:[reportInfo playerId]];
    }
//    [[PoolChecker getInstance] reportOpen];
    [_interface SDKreport:reportInfo];
    
}

- (void)gotoUserCenter
{
    [_interface SDKgotoUserCenter];
}

- (void)logoutSDK
{
    [_interface SDKlogoutSDK];
}

- (void)exitSDK
{
    [_interface SDKexitSDK];
}

- (void)handleOpenurl:(NSURL *)url
{
    NSLog(@"handleOpenurl%@",url);
    if([[url host] isEqualToString:@"c_code"]){
        NSString* path = url.path;
        NSString* codeValue = [path substringFromIndex:1];
        [[PoolChecker getInstance] handleFirstOpenApp:codeValue];
    }
    [_interface handleOpenurl:url];
}

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return [_interface application:application supportedInterfaceOrientationsForWindow:window];
}

- (NSString *)getGameChannelId{
    return [[PoolConfig getInstance]getValueByKey:@"gamechannelid"];
}

- (NSString *)getCustomValue{
    return [[PoolConfig getInstance]getValueByKey:@"custom"];
}

- (NSString *)getChannelParameter1{
    return [[PoolConfig getInstance]getValueByKey:@"c1"];
}

- (NSString *)getChannelParameter2{
    return [[PoolConfig getInstance]getValueByKey:@"c2"];
}

@end