标签:win 根据 root 支付插件 resign nat ring ntc options
引用头文件:
#import <HN669SDKCore/HN669SDKCore.h>
初始化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:@"HN669SDK"]; [[HN669SDK sharedInstance] initWithParams:sdkconfig]; [[HN669SDK sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; [[HN669Analytics sharedInstance] startLevel:@"1"]; self.window.rootViewController = [[ViewController alloc] init]; return YES; }
AppDelegate事件处理
需要在AppDelegate以下对应的生命周期方法中调用HN669SDK种对应这些方法:
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[U8SDK sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } -(void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo { [[U8SDK sharedInstance] application:application didReceiveRemoteNotification:userInfo]; } -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [[U8SDK sharedInstance] application:application didReceiveRemoteNotification:userInfo]; } -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [[U8SDK sharedInstance] application:application didReceiveLocalNotification:notification]; } - (void)applicationWillResignActive:(UIApplication *)application { [[U8SDK sharedInstance] applicationWillResignActive:application]; } - (void)applicationDidEnterBackground:(UIApplication *)application { [[U8SDK sharedInstance] applicationDidEnterBackground:application]; } - (void)applicationWillEnterForeground:(UIApplication *)application { [[U8SDK sharedInstance] applicationWillEnterForeground:application]; } - (void)applicationDidBecomeActive:(UIApplication *)application { [[U8SDK sharedInstance] applicationDidBecomeActive:application]; } - (void)applicationWillTerminate:(UIApplication *)application { [[U8SDK sharedInstance] applicationWillTerminate:application]; } -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [[U8SDK sharedInstance] application:application handleOpenURL:url]; } -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [[U8SDK sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; }
2.游戏主界面viewController
实现HN669SDKDelegate协议,并且实现协议中定义的方法,在ViewController中的viewDidLoad方法中调用:
[[HN669SDK sharedInstance] setDelegate:self];
实现协议方法:
这些协议回调根据渠道可能会有,也可能不回掉
#pragma mark --<HN669SDKDelegate> -(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{ }
调用登录接口,打开SDK登录界面
[[HN669SDK sharedInstance] login];
调用登录接口,打开SDK登录界面
[[U8SDK sharedInstance].defaultUser login];
SDK登录成功的回调,通过Notification通知到抽象层中,可以在上面OnUserLogin回调中进行处理。这个时候,应该去U8Server做二次登录认证
部分渠道没有支持切换账号接口,那么切换账号默认调用的接口和登录相同。
[[U8SDK sharedInstance].defaultUser switchAccount];
切换账号成功的回调,和登录的回调相同,都是在OnUserLogin中处理
部分渠道没有登出接口,那么登出接口默认不做任何实现
[[U8SDK sharedInstance].defaultUser logout];
登出成功的回调,在上面OnUserLogout回调方法中处理
调用该方法时,先判断当前渠道是否提供了个人中心接口:
if([[U8SDK sharedInstance].defaultUser hasAccountCenter])
{
[[U8SDK sharedInstance].defaultUser showAccountCenter];
}
在调用支付的时候,和Android一样,游戏中需要传入对应的参数,然后调用支付插件的pay方法:
[[U8SDK sharedInstance].defaultPay pay:dic]; //参数dic是一个NSDictionary结构
支付成功的回调,可以在上面OnPayPaid回调方法中进行处理。一般网游这里不需要做特殊的处理,因为支付是异步的,这里支付成功,仅仅是SDK支付请求成功,并不代表玩家得到了游戏币。真正充值成功,是异步通知到游戏服务器的。
参数Key | 参数类型 | 参数说明 |
---|---|---|
productId | String | 充值商品ID,游戏内的商品ID |
productName | String | 商品名称,比如100元宝,500钻石... |
productDesc | String | 商品描述,比如 充值100元宝,赠送20元宝 |
price | int | 充值金额(单位:元) |
ratio | int | 兑换比例,暂时无用途 |
buyNum | int | 购买数量,一般都是1 |
coinNum | int | 玩家当前身上剩余的游戏币 |
serverID | String | 玩家所在服务器的ID |
serverName | String | 玩家所在服务器的名称 |
roleID | String | 玩家角色ID |
roleName | String | 玩家角色名称 |
roleLevel | String | 玩家角色等级 |
vip | String | 玩家vip等级 |
payNotifyUrl | String | 支付回调地址,下单时,U8Server返回的 |
orderID | String | U8Server订单号,下单时,U8Server返回的 |
extension | String | 渠道相关的扩展数据,下单时,U8Server返回的 |
标签:win 根据 root 支付插件 resign nat ring ntc options
原文地址:http://www.cnblogs.com/liuluoxing/p/7169447.html