JHToolsSDK API调用

调用API
1.Appdelegate中调用以下方法

引用头文件:
#import 
 
初始化SDK
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
     
    //初始化应该在程序启动时调用, 也就是在didFinishLaunchingWithOptions方法里
    NSDictionary *sdkconfig = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"JHToolsSDK"];
    [[JHToolsSDK sharedInstance] initWithParams:sdkconfig];
    [[JHToolsSDK sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    [[JHToolsAnalytics sharedInstance] startLevel:@"1"];
     
    self.window.rootViewController = [[ViewController alloc] init];
    return YES;
}

AppDelegate事件处理:
需要在AppDelegate以下对应的生命周期方法中调用JHToolsSDK种对应这些方法:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [[JHToolsSDK sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
 
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
{
    [[JHToolsSDK sharedInstance] application:application didReceiveRemoteNotification:userInfo];
}
 
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    [[JHToolsSDK sharedInstance] application:application didReceiveRemoteNotification:userInfo];
}
 
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    [[JHToolsSDK sharedInstance] application:application didReceiveLocalNotification:notification];
}
 
- (void)applicationWillResignActive:(UIApplication *)application {
    [[JHToolsSDK sharedInstance] applicationWillResignActive:application];
}
 
- (void)applicationDidEnterBackground:(UIApplication *)application {
    [[JHToolsSDK sharedInstance] applicationDidEnterBackground:application];
}
 
- (void)applicationWillEnterForeground:(UIApplication *)application {
    [[JHToolsSDK sharedInstance] applicationWillEnterForeground:application];
}
 
- (void)applicationDidBecomeActive:(UIApplication *)application {
    [[JHToolsSDK sharedInstance] applicationDidBecomeActive:application];
}
 
- (void)applicationWillTerminate:(UIApplication *)application {
    [[JHToolsSDK sharedInstance] applicationWillTerminate:application];
}
 
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [[JHToolsSDK sharedInstance] application:application handleOpenURL:url];
}
 
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [[JHToolsSDK sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options{
    return [[JHToolsSDK sharedInstance] application:application openURL:url options:options];
}
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return [[JHToolsSDK sharedInstance] application:application supportedInterfaceOrientationsForWindow:window];
}

2.游戏主界面viewController

实现JHToolsSDKDelegate协议,并且实现协议中定义的方法,在ViewController中的viewDidLoad方法中调用:

[[JHToolsSDK sharedInstance] setDelegate:self];

实现协议方法:
这些协议回调根据渠道可能会有,也可能不回掉
#pragma mark --
-(UIView*) GetView{
    return [self GetViewController].view;;
}
 
-(UIViewController*) GetViewController{
    return self;
}
 
//SDK初始化成功回调
-(void) OnPlatformInit:(NSDictionary*)params{
}
 
//登录成功回调
-(void) OnUserLogin:(NSDictionary*)params{
}
 
//登出回调
-(void) OnUserLogout:(NSDictionary*)params{
}
 
//支付回调
-(void) OnPayPaid:(NSDictionary*)params{
}
 
//事件回调
-(void) OnEventCustom:(NSString*)eventName params:(NSDictionary*)params{
}

3.用户功能API调用

1) 登录(必须实现)
调用登录接口,打开SDK登录界面 
[[JHToolsSDK sharedInstance] login];
2) 切换账号(必须实现)
部分渠道没有支持切换账号接口,那么切换账号默认调用的接口和登录相同。 
[[JHToolsSDK sharedInstance] switchAccount];
3) 登出(非必需实现)
部分渠道没有登出接口,那么登出接口默认不做任何实现
[[JHToolsSDK sharedInstance] logout];
4) 显示个人中心
Note: 部分渠道要求游戏内必须要有[个人中心]按钮,点击进入渠道SDK的个人中心界面.但是因为是部分渠道有这个接口,部分渠道没有提供这个接口,所以,对于没有提供该接口的渠道,该方法不做任何逻辑。
游戏层需要根据支付支持该方法的判定,来显示或者隐藏该按钮。
调用该方法时,先判断当前渠道是否提供了个人中心接口: 
if([[JHToolsSDK sharedInstance].defaultUser hasAccountCenter])
    {
        [[JHToolsSDK sharedInstance] showAccountCenter];
    }
5)支付接口
在调用支付的时候,游戏中需要传入对应的参数,然后调用支付插件的pay方法:
    JHToolsProductInfo* productInfo = [[JHToolsProductInfo alloc] init];
    productInfo.orderID = @"1782341234";
    productInfo.productName = @"礼包1";
    productInfo.productDesc = @"礼包1";
    productInfo.productId = @"com.669.jianqilingyun.600";
    productInfo.price = [NSNumber numberWithInt:1];
    productInfo.buyNum = 1;
    productInfo.coinNum = 900;
    productInfo.roleId = @"12345";
    productInfo.roleName = @"角色";
    productInfo.roleLevel = @"66";
    productInfo.serverId = @"1";
    productInfo.serverName = @"桃源";
    productInfo.vip = @"1";
    productInfo.extension = @"hjghjklhjk";
    productInfo.notifyUrl = @"http://110.54.33.45/game/pay/notify";
    [[JHToolsSDK sharedInstance] pay:productInfo];
    //参数dic是一个JHToolsProductInfo对象 支付成功的回调,可以在上面OnPayPaid回调方法中进行处理。一般网游这里不需要做特殊的处理,因为支付是异步的,这里支付成功,仅仅是SDK支付请求成功,并不代表玩家得到了游戏币。真正充值成功,是异步通知到游戏服务器的。

关于支付参数的说明:![屏幕快照 2019-09-25 上午9.01.16.png](https://upload-images.jianshu.io/upload_images/5873349-2d8dbad1b3043e32.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

6)提交用户数据,用户登录、进入游戏、升级、退出游戏时候调用 
    JHToolsUserExtraData* extraData = [[JHToolsUserExtraData alloc] init];
    extraData.dataType = TYPE_ENTER_GAME;
    extraData.roleID = @"testRole";
    extraData.roleName = @"角色名称";
    extraData.serverID = 1;
    extraData.serverName = @"第一区";
    extraData.roleLevel = @"1";
    extraData.moneyNum = 100;
    extraData.roleCreateTime = time(NULL);
    extraData.roleLevelUpTime = time(NULL);
    [[JHToolsSDK sharedInstance] submitExtraData:extraData];

NOTE:选择服务器时,因为还没有进入游戏,无法知道角色数据,extraData中只需要传入服务器信息即可。
![屏幕快照 2019-09-25 上午9.08.13.png](https://upload-images.jianshu.io/upload_images/5873349-f6bb221485a81bbc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

你可能感兴趣的:(JHToolsSDK API调用)