CWSDK集成文档

2018-10-15  本文已影响0人  JohnSnow_b20c

pod安装

SDK集成需安装cocoapods
注意安装完成后, 需要在终端 执⾏ pod setup, 要下载几百兆个样子, 比较久

pod setup

开始集成CWSDK(为方便脚本混淆代码, 更改过类名, 现在SDK名字是CMKOASDK)

以CWSDKDemo工程为例:

pod init

目录会多出Podfile文件, 编辑Podfile

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
use_frameworks!

target 'Unity-iPhone' do
    pod 'CMKOASDK', :path => '../'
end
pod update
#import <CMKOASDK/CMKOASDK.h>
#pragma mark - UIApplicationDelegate
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    [[CMKOASDK sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    [[CMKOASDK sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error];
}
- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options
{
    [[CMKOASDK sharedInstance] application:app openURL:url options:options];
    return YES;
}
[[CMKOASDK sharedInstance] setDelegate:self];
// 返回当前显示控制器的View
- (UIView*)cmkoa_currentView;
// 返回当前显示的控制器
- (UIViewController*)cmkoa_currentViewController;
[[CMKOASDK sharedInstance] login];

// SDK登录成功回调, 数据包含在notification.userInfo中
- (void)OnUserLogin:(NSNotification *)notification
{
    NSLog(@"Login userInfo: %@", notification.userInfo);
    // 游戏登录逻辑
}
// SDK登出回调
- (void)OnUserLogout:(NSNotification *)notification {
    // 需调用游戏退出登录逻辑, 到sdk登录界面
    
}
- (void)U3D_logout {
    // 调用SDK退出登录
    [[CMKOASDK sharedInstance] logout];
}
#pragma mark - 更新角色信息
///上传玩家信息(必须,在选择完服务器,正式进入游戏时候调用)
- (void)uploadRoleData {
    // 角色 id
    NSString *roleId = nil;
    // 角色名
    NSString *roleName = nil;
    // 角色等级
    NSString *roleLv = nil;
    // 服务器 id
    NSString *serverId = nil;
    // 服务器名称
    NSString *serverName = nil;
    // 工会
    NSString *society = nil;
    // 角色 vip 等级
    NSString *vipLv = nil;
    // 战力
    NSString *power = nil;
    // 游戏渠道id(可不填)
    NSString *cpChannelID = nil;
    [[CMKOASDK sharedInstance] updateRole:@{
                                             @"roleID": roleId,
                                             @"roleName": roleName,
                                             @"roleLevel": roleLv,
                                             @"serverID": serverId,
                                             @"serverName":serverName,
                                             @"society": society,
                                             @"vip": vipLv,
                                             @"power": power,
                                             @"cpChannelID": cpChannelID
                                             }];
}
#pragma mark - 显示客服
-(void)showCustomService {
    [[CMKOASDK sharedInstance] showCustomerSupport];
}
#pragma mark - 账号管理
-(void)showAccountCenter {
    id<CMKOALoginManagerDelegate> manager = [CMKOASDKLoginManager sharedManager];
    if ([manager respondsToSelector:@selector(showBindingDialog)]) {
        [manager showBindingDialog];
    }
}
#pragma mark - 打点
// 角色升级
-(void)roleUpgrade:(NSString*)lv {
    id<CMKOAAnalytics> analyticsDelegate = [CMKOASDK sharedInstance].analyticsDelegate;
    if ([analyticsDelegate respondsToSelector:@selector(cmkoa_levelUp:)]) {
        [analyticsDelegate cmkoa_levelUp:lv.intValue];
    }
}

// 完成新手引导
- (void)guideFinish {
    id<CMKOAAnalytics> analyticsDelegate = [CMKOASDK sharedInstance].analyticsDelegate;
    if ([analyticsDelegate respondsToSelector:@selector(cmkoa_completeBeginnerGuide)]) {
        [analyticsDelegate cmkoa_completeBeginnerGuide];
    }
}

#pragma mark - 调起支付
-(void)charge:(类名 *)orderInfo {
    // 商品名称
    NSString *productName = nil;
    // 商品价格
    NSString *price       = nil;
    // 游戏商品id
    NSString *cpProductId = nil;
    // 商品描述
    NSString *productDesc = nil;
    // cw订单号
    NSString *orderID     = nil;
    // extension字段(具体参考CWSDK文档-服务器 - 统一下单接口(游服->CWServer) )
    NSString *paymentStr  = nil;
    
    CMKOAProductInfo* productInfo = [[CMKOAProductInfo alloc] init];
    productInfo.currencyCode      = [CMKOAServerConfig currentConfig].currencyCode;
    productInfo.productName       = productName;
    productInfo.price             = price;
    productInfo.productDesc       = productDesc;
    productInfo.orderID           = orderID;
    productInfo.cpProductId       = cpProductId;
    productInfo.paymentStr        = paymentStr;

    [[CMKOASDK sharedInstance] showPaymentViewControllerWithProductInfo:productInfo];
}
// 支付成功--客户端收到钻石后调用此方法
- (void)onOrderPaySucc {
    [[CMKOASDK sharedInstance] finishPayment];
}
上一篇下一篇

猜你喜欢

热点阅读