1.接入龙图iOSSDK的游戏及应用的iOS客户端开发者。
2.使用此文档内接口,需要先接入龙图iOSSDK(详情查看龙图iOSSDK文档,当前支持龙图官网最新版本)。
3.接入龙图iOSSDK后,需要配置GSWalletSDK需要的依赖库。
注:PocketBuff iOS终端SDK接入教程,只涉及SDK的使用方法。
appid:必须参数,联系运营支持获取.
在官网下载对应SDK和demo
1、需要引入的三方库
2、必须在 Xcode Build Settings 里面 Other Linker Flags 设置值 -ObjC。
该项如果设置错误,运行时就会出现异常:unrecognized selector sent to instance exception
3、添加URL TYPE
在 Xcode 中,选择你的工程设置项,选中TARGETS一栏,在 Info 标签栏的 URL Types 中添加identifier为”gswallet” , URL Scheme 为 “gsw + 你所注册的应用程序 AppId”(如下图所示):
如 AppId 为 1234567890,则 URL Scheme 设置为 gsw1234567890
4、添加白名单
<key>LSApplicationQueriesSchemes</key><array><string>com.pocketbuff.pbwallet</string><string>pbwallet</string></array>
5、配置区块链登录识别参数(与Wemix共用同一配置)
<key>LTBase_WemixLogin</key><true/>
如果使用PocketBuff请设置布尔值为true
6、PocketBuff钱包debug日志控制配置
如果打开PocketBuff钱包的debug日志(不同于龙图SDK,仅限于打开PocketBuff钱包日志)输出请设置布尔值为true
<key>LTbase_GSWalletDebug</key><true/>
接口介绍
/*** 启动接口*/// 正式模式,与测试模式二选一,不能同时接入- (BOOL)LTGSWalletApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;// 测试模式,与正式模式二选一,不能同时接入- (BOOL)LTGSWalletDebugTest:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
示例
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{// 正式模式,与测试模式二选一,不能同时接入[[LTGSWalletSDK sharedInstance] LTGSWalletApplication:application didFinishLaunchingWithOptions:launchOptions];// 测试模式,与正式模式二选一,不能同时接入[[LTGSWalletSDK sharedInstance] LTGSWalletDebugTest:application didFinishLaunchingWithOptions:launchOptions];}
/*** 生命周期跳转链接接口*/- (BOOL)LTGSWalletApplication:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;- (BOOL)LTGSWalletApplication:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;- (BOOL)LTGSWalletApplication:(UIApplication *)application handleOpenURL:(NSURL *)url;
示例
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{return [[LTGSWalletSDK sharedInstance] LTGSWalletApplication:application handleOpenURL:url];}- (BOOL)application:(UIApplication *)application openURL:(NSURL *)urlsourceApplication:(NSString *)sourceApplication annotation:(id)annotation{return [[LTGSWalletSDK sharedInstance] LTGSWalletApplication:application openURL:url sourceApplication:sourceApplication annotation:annotation];}- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options{return [[LTGSWalletSDK sharedInstance] LTGSWalletApplication:app openURL:url options:options];}
/// 签名接口/// @param viewController 当前控制器/// @param prepayId prepayId 通过服务器获取/// @param nonce nonce 通过服务器获取/// @param sign sign 通过服务器获取/// @param timestamp 时间戳 通过服务器获取- (void)LTGSWalletSendPayRequest:(UIViewController *)viewController prepayId:(NSString *)prepayId nonce:(NSString *)nonce sign:(NSString *)sign timestamp:(NSUInteger)timestamp;
示例
[[LTGSWalletSDK sharedInstance] LTGSWalletSendPayRequest:self prepayId:@"通过服务器获取" nonce:@"通过服务器获取" sign:@"通过服务器获取" timestamp:通过服务器获取];
代理方法
声明和设置代理@interface ViewController ()<LTGSWalletSDKDelegate>@end[LTGSWalletSDK sharedInstance].delegate = self;实现代理- (void)LTGSWalletSDKSignInWithGSWalletCallBack:(NSDictionary *)dict code:(NSInteger)code result:(BOOL)result {/*错误码:100.成功102.授权失败103.签名失败105.授权服务端查询请求失败(具体失败原因见服务端返回)106.授权服务端绑定请求失败107.用户取消首次绑定GS108.用户取消三方绑定游客110.用户三方绑定游客失败111.点击关闭绑定页面112.打开绑定页面失败113.当前用户已经绑定了其他PocketBuff 账号114.当前PocketBuff账号 ,已经被绑定*//*失败格式dict :{error = "\U70b9\U51fb\U5173\U95ed\U7ed1\U5b9a\U9875\U9762";}成功格式dict :{transactionId = "";customId = ;GSPay = "1";//此参数用来区分授权和签名,为空或!=1时是授权,=1时为签名}*/NSLog(@"LTWeMixSDKSignInWithWemixCallBack dict :%@,code:%ld",dict,(long)code);if(result){[self showMessage:[NSString stringWithFormat:@"msg:成功;code:%ld",(long)code]];}else{[self showMessage:[NSString stringWithFormat:@"msg:%@;code:%ld",dict[@"error"],(long)code]];}}
接口介绍
/// 查询绑定状态接口- (void)LTGSWalletSignInWithGSWalletCheckBind;
示例说明
//查询绑定[[LTGSWalletSDK sharedInstance] LTGSWalletSignInWithGSWalletCheckBind];
/// 绑定接口/// @param viewController 控制器- (void)LTGSWalletBindGSWallet:(UIViewController *)viewController;
示例说明
//绑定GSWallet[[LTGSWalletSDK sharedInstance] LTGSWalletBindGSWallet:UIViewController];
//代理回调
//声明和设置代理(同之前代理设置,无需额外设置)@interface ViewController ()<LTGSWalletSDKDelegate>@end[LTGSWalletSDK sharedInstance].delegate = self;//实现代理/// 绑定状态/绑定结果/// @param type 回调类型 0=查询绑定状态回调;1=绑定GSWallet结果回调/// @param code code 1=请求成功,=其他为失败状态/// @param message 描述信息/// @param isBind 是否已绑定(type=0)/是否绑定成功(type=1);返回yes代表成功,accessToken,openId和tokenType,返回no则参数为空字符/// @param dict 返回参数accessToken/openId/tokenType- (void)LTGSWalletSDKSignFromGSWalletWithType:(NSString *)type code:(NSInteger)code message:(NSString *)message isBind:(BOOL)isBind dict:(NSDictionary *)dict {NSLog(@"LTGSWalletSDKSignFromGSWalletWithType type:%@ isBind:%@ code:%ld msg:%@ dict :%@,",type,isBind ? @"yes" : @"no",(long)code,message,dict);if ([type isEqualToString:@"0"]) {//查询if (code == 1) {if (isBind) {//已绑定[self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"yes" ,message,code]];}else{//未绑定[self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];}}else{//查询失败[self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];}}else{//单独绑定if (code == 1) {//绑定if (isBind) {//绑定成功[self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"yes" ,message,code]];}else{//绑定失败[self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];}}else{//绑定失败[self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];}}/*错误码:1.成功102.授权失败105.授权服务端查询请求失败(具体失败原因见服务端返回)106.授权服务端绑定请求失败107.用户取消首次绑定PocketBuff108.用户取消三方绑定游客110.用户三方绑定游客失败111.点击关闭绑定页面112.打开绑定页面失败113.当前用户已经绑定了其他PocketBuff 账号114.当前PocketBuff账号 ,已经被绑定*//*失败格式dict :{//返回空字符accessToken = "";expire = 0;openId = "";tokenType = "";walletAddress = "";}成功格式dict :{accessToken = 40959dbdf6654db7833efee42ec6428d;expire = 0;openId = 221112314949953;tokenType = "";walletAddress = 0x8A895C5239d9EBCC22eE58Da08A2d4C978e916fE;}*/}
返回字典格式说明
| 参数 | 类型 | 说明 |
|---|---|---|
| walletAddress | NSString | 用户钱包地址 (1.0.2版本新增) |
| accessToken | NSString | 如果绑定了才有值,返回绑定的PocketBuff用户token |
| openId | NSString | 如果绑定了才有值,返回绑定的PocketBuff用户openid |
| tokenType | NSString | 如果绑定了才有值,返回绑定的PocketBuff用户 Token 类型,bearer |
| expire | NSString | accessToken 是否过期, 1 过期了, 0 没有过期。 如果token已经过期, 在签名的时候需要重新绑定失败的时候默认返回0 |
发送在 GS 钱包 App 内置的浏览器中打开指定网页的请求
/// 打开网址/// @param url 链接地址/// @param completion 回调- (void)LTGSWalletOpenWebViewRequest:(NSString *)url completion:(void (^ __nullable)(NSError *error))completion;
示例说明
[[LTGSWalletSDK sharedInstance] LTGSWalletOpenWebViewRequest:@"网址" completion:^(NSError *error) {if (error) {NSLog(@"GSWalletViewController LTGSModelOpenWebViewRequest 失败 %@",error.description);}}] ;
检查GS钱包APP是否已被用户安装
BOOL isInstall = [[LTGSWalletSDK sharedInstance] LTGSWalletIsAppInstalled];
返回app下载地址
NSString *appUrl = [[LTGSWalletSDK sharedInstance] LTGSWalletGetAppInstallURL];
| 状态码 | 说明 |
|---|---|
| 1 | 成功(查询绑定状态和绑定PocketBuff回调) |
| 100 | 成功(授权回调) |
| 102 | 授权失败 |
| 103 | 签名失败 |
| 105 | 授权服务端查询请求失败(具体失败原因见服务端返回) |
| 106 | 授权服务端绑定请求失败 |
| 107 | 用户取消首次绑定PocketBuff |
| 108 | 用户取消三方绑定游客 |
| 110 | 用户三方绑定游客失败 |
| 111 | 点击关闭绑定页面 |
| 112 | 打开绑定页面失败 |
| 113 | 当前用户已经绑定了其他PocketBuff 账号 |
| 114 | 当前PocketBuff账号 ,已经被绑定 |

上海中清龙图软件有限公司